I have a question about Unity Container. My MVC application starts on Application_Start at Global.asax which is a container of Unity Container that works like below
_container = new UnityContainer();
_container.RegisterType(typeof(MainBCUnitOfWork), new PerResolveLIfeTimeManager());
From what I know, IIS will instantiate the type MainBCUnitOfWork only one time on its life cycle and will utilize the same instance in all requests, which is why I am using LifeTimeManager of type PerResolveLifeTimeManager.
My application has always worked well in this mode, however I am trying to utilize shared database access / cross database access where the required access will come from a (session, querystring) and change the database with the method below:
public void ChangeDatabase(string database)
{
Database.Connection.ConnectionString = "server=localhost;User Id=root;password=mypassword;Persist Security Info=True;database=" + database;
}
On my local testing everything works ok, but I have questions when in production if IIS processing many requests at the same time.
I did some research and found references where IIS only process one request each time, and if needed to process more than one request I should activate Web Garden, but this would bring other problems. See this link IIS and HTTP pipelining, processing requests in parallel
My question is, does IIS server only process one request each time, independent of the source?
The change of database during execution time can interfere with prior requests which are still ongoing?
I use Utity 2 wich does not have PerRequestLIfetimeManager, which would instantiate MainBCUnitOfWork per each request, which is sugested here MVC, EF - DataContext singleton instance Per-Web-Request in Unity
In case I update for a newer version and utilize one instance per request, what would be the impact on my performance?
What is recommended for this situation?