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.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.