I have layered asp.net MVC application. In the service layer, I have a container to register dependencies. e.g:
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterType<ISomething, Something>();
}
Based on the design, we need to have a mock implementation of the classes if the user decided to open the application for testing purpose.
So, I came up with an Idea like
public static void RegisterTypes(IUnityContainer container)
{
container.RegisterType<ISomething, Something>();
container.RegisterType<ISomething, SomethingMock>();
}
If I use a flag somewhere to indicate whether or not system runs at testing mode, how can I make a decision on which dependency to resolve at the runtime? If it is not an elegant solution, what could be the alternative?