Question

I can do this in 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 });

Is this possible in Unity? I've tried doing it but it complains that it can't find the constructor. It seems I can only inject via the sub-type.

Was it helpful?

Solution

You can only inject via the sub-type. It needs a public constructor.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top