1

ウィンザー城でこれを行うことができます:

public abstract class AbstractFactory
{
    protected AbstractFactory(Foo constructorParm)
    {
        // Do something with parameter...
    }
}

public class DescendentFactory : AbstractFactory
{
    public DescendentFactory(Foo constructorParm) : base(constructorParm)
    {
    }
}

// The container is configured via XML, the service AbstractFactory and the
// type DescendentFactory
container.Resolve<AbstractFactory>("DescendentFactoryId", new { constructorParm = injectedValue });

これはUnityで可能ですか?私はそれをやろうとしましたが、コンストラクターが見つからないと不平を言います。サブタイプ経由でしか注入できないようです。

4

1 に答える 1

2

サブタイプを介してのみ注入できます。public コンストラクターが必要です。

于 2010-11-23T11:22:01.630 に答える