我可以在Castle Windsor做到这一点:
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中可行吗?我试过这样做,但它抱怨它找不到构造函数。看来我只能通过子类型注入。
答案 0 :(得分:2)
您只能通过子类型注入。它需要一个公共构造函数。