We have a multi-company capable site which requires unique business logic for each company. We are using constructor dependency injection in our controllers, but would need to swap the unity container being used based upon a user's company. I was thinking that you could examine the user's cookie before setting the container for the current HttpContext. Is this even possible?
-
Do you mean that you don't run the websites of different companies in different environments? It is actually the same "instance" of the website for every visitor?Sebastian Weber– Sebastian Weber2012-06-04 11:08:36 +00:00Commented Jun 4, 2012 at 11:08
-
That is the intent. We could setup different front end sites for each company, but were hoping to integrate them all under the same front end so that the "super admins" can log into one tool and change company settings for whichever company they choose.wigs– wigs2012-06-04 11:27:37 +00:00Commented Jun 4, 2012 at 11:27
1 Answer
It's very doable. What I'd do is set up a "master" container, and then a child container for each company. That way you have default configuration in one place, and then you can customer per company easily without having to reconfigure every time. Save the child containers in some easily indexed way (a dictionary of company -> container, perhaps).
Then, write an HttpModule implementation that runs early in the pipeline to figure out which company the request is for. Use that to figure out the appropriate container to use. And from there you're pretty much set.
I would be worried as a customer of your system that you're not isolating my data sufficiently; wouldn't want to leak information across customers and get sued.
4 Comments
HttpModule. How do you make it accessible to an ASP.NET Web Forms (not MVC) application? Where do you store it across requests? I understood that initializing the container (I'm referring to Unity here but I think its the same for other containers) is expensive so you would try to minimize the performance impact and initialize it only once.