0

I need resolve various calls to my class constructor "UnitOfWork" as you can see in the example:

container.RegisterType<IDbContext, NorthwindContext>("NorthwindContext");
container.RegisterType<IDbContext, NorthwindCustomerContext>("NorthwindCustomerContext");

container.RegisterType<IUnitOfWork, UnitOfWork>(
    "NorthwindUnitOfWork", 
    new InjectionConstructor(container.Resolve<IDbContext>("NorthwindContext")));

container.RegisterType<IUnitOfWork, UnitOfWork>(
    "NorthwindCustomerUnitOfWork", 
    new InjectionConstructor(container.Resolve<IDbContext>("NorthwindCustomerContext")));

But now I need to add new parameter to the constructor, like this:

container.RegisterType<IOtherParameter, OtherParameter>();

container.RegisterType<IUnitOfWork, UnitOfWork>(
    "NorthwindUnitOfWork", 
    new InjectionConstructor(
        container.Resolve<IDbContext>("NorthwindContext"), 
        container.Resolve<IOtherParameter>()
    ));

How can I do if I have many parameters but I only need resolve one and avoid calling container.Resolve repeatedly?, like the first example, because IOtherParameter only has one option (RegisterType). Other respondents like this saw the library using SmartConstructor of tecx, but would need to know if there is any solution in Unity 3 to avoid adding an additional library.

Community
  • 1
  • 1
andres descalzo
  • 14,887
  • 13
  • 64
  • 115
  • 1
    Possible duplicate of [Unity: Implicit ResolvedParameter for unnamed registrations](http://stackoverflow.com/questions/21905504/unity-implicit-resolvedparameter-for-unnamed-registrations/22030760). – TylerOhlsen Apr 21 '14 at 21:05
  • @TylerOhlsen I tried that you sent and it works fine, thanks, now I pass the question as a duplicate – andres descalzo Apr 24 '14 at 18:47

0 Answers0