I am using the following in my controller
IAccountRepository AcctRep;
IAccountProductRepository AcctProdRep;
public HomeController(IUnityContainer container)
{
AcctRep = container.Resolve<IAccountRepository>();
AcctProdRep = container.Resolve<IAccountProductRepository>();
}
and in my UnityConfig.cs file in the AppStart..
container.RegisterTypes(AllClasses.FromLoadedAssemblies(),
WithMappings.FromMatchingInterface,
WithName.Default);
Why?
To Save myself from manually registering about 30 different repositories in UnityConfig.cs like below:
container.RegisterType< IAccountRepository, AccountRepository >();
To Save my Self the Hassle of doing the below in countless controllers
IAccountRepository AcctRep; IAccountProductRepository AcctProdRep; public HomeController(IAccountRepository acctRep, IAccountProductRepository acctProdRep) { AcctRep = acctRep; AcctProdRep = acctProdRep; }
and because what i proposed looks neater than above (imagine having to inject 4 Repositories)...
Question is am i having too much of a performance issue, or anything that I am not seeing and can regret in the future?
Edit A little part of this question is similar to the suggested duplicate but not entirely.. I.e. the using of Unity's AllClasses mappings and performance impact of doing the above vs the normal injection and issues I might face in the future if I go down that way.. @Konamiman's approach to the answer is very neat keeping question to see what others have to say..