I'm looking for a way to switch settings dynamically from an MVC web app which uses Unity IoC container.
I have a static instance of the container which is configured in Global.asax.cs
private static IUnityContainer _container;
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
InitializeUnityContainer();
}
and then a custom controller factory
protected override IController GetControllerInstance(
RequestContext reqContext, Type controllerType)
{
// ... 开发者_StackOverflow中文版(some argument checking here)
return _container.Resolve(controllerType) as IController;
}
We have different teams within the company who all use their own database servers (with identical schemas). The proposed solution from management is to have multiple instances of the web app running, so you go to whichever URL for your specific team. I'd rather run only one web app and have the teams select which database (and other config settings) they want the app to connect on (ideally through a drop down or some type of menu).
I'm a bit stumped as to how I could acheive this though. The unity container would need to be configured differently for each team (maybe I'd need mutliple static instances?) and other configuration setting accessed directly in the controllers would need to change. I would guess this must be a relatively common problem, is there a standard solution?
I don't think hosting all the teams in a single application will work well - anything you have that is not request-scoped will not work correctly - eg. any Application-scoped data or static fields could cause issues, being set by only the first visitor, or overridden constantly..
The cleanest way would definitely to have multiple Applications (even if they point to the same codebase).
精彩评论