0

having the following classes and interfaces:

private class ClassToResolve
{
    public ClassToResolve(ConstructorArgument arg1, ConstructorArgument arg2, IConstructorArgument2 arg3)
    {
    }
}

private class ConstructorArgument
{
}

private class ConstructorArgument2 : IConstructorArgument2
{
}

private interface IConstructorArgument2
{
}

Imagine that I have the following registration:

UnityContainer container = new UnityContainer();

container.RegisterType<IConstructorArgument2, ConstructorArgument2>("A");
container.RegisterType<IConstructorArgument2, ConstructorArgument2>("B");

// How to register this?
container.RegisterType<ClassToResolve, ClassToResolve>(...

ClassToResolve result = container.Resolve<ClassToResolve>();

I'm trying a way to not have to usean InjectionContructor that forces me to put all the contructor arguments as this is becoming a nightmare on the project we are working as everytime dependencies change we have to modify lots of registrations.

In this case I would like to have a way to do something like: container.RegisterType<ClassToResolve, ClassToResolve>(new ResolvedParameter<IConstructorArgument2>("arg3", "A");

Is this possible with the UnityContainer or writting an extension to it?

Thanks.

Ignacio Soler Garcia
  • 21,122
  • 31
  • 128
  • 207
  • refer to http://stackoverflow.com/questions/2280170/why-do-we-need-abstract-factory-design-pattern – daryal Jun 17 '14 at 08:44
  • @daryal: nice post but this time I don't have problems with run-time data but with different registered names. I want to avoid writing all the constructor parameters just because one needs a name to be resolved. – Ignacio Soler Garcia Jun 17 '14 at 08:49
  • possible duplicate of [Unity: Implicit ResolvedParameter for unnamed registrations](http://stackoverflow.com/questions/21905504/unity-implicit-resolvedparameter-for-unnamed-registrations) – Ignacio Soler Garcia Jun 17 '14 at 10:43

0 Answers0