69917

MVC3, Unity Framework with multiple configurations

Question:

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?

Answer1:

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.

Recommend

  • Can an entity be unloaded from entity framework's ObjectStateManager?
  • jquery ajax bug
  • view SQLite Databases in android listview?
  • How do I see existing classes
  • IIS7 Application Request Routing HTTPS
  • something very wrong with SESSIONS
  • Copying rows in a database when rows have children
  • Passing information to server-side function in a Google Docs Add On
  • CRASH: *** -[__NSArrayM objectAtIndex:]: index 4294967295 beyond bounds [0 .. 9]
  • Why doesnt this Java loop in a thread work?
  • Mixing WebForms and MVC: What should I do with the MasterPage?
  • C#: Import/Export Settings into/from a File
  • Syntax error on tokens, AnnotationName expected instead - error on query
  • JSR-330 support in Picocontainer : @Inject … @Named(\"xxx)
  • Sending cookie value via httpget but not getting the desired response
  • How to get links to open in the native browser in iOS Meteor apps?
  • How can I display the parent menu item's description using Wordpress walkers?
  • uniform generation of points on 3D box
  • SharedPreferences or SQLite Database?
  • WPF - CanExecute dosn't fire when raising Commands from a UserControl
  • Use of this Javascript
  • C++ Partial template specialization - design simplification
  • Ajax Loaded meta Tags
  • Q promise. Difference between .when and .then
  • Xamarin Forms - UWP Fonts
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Spray.io: When (not) to use non-blocking route handling?
  • Modifying destination and filename of gulp-svg-sprite
  • 'TypeError' while using NSGA2 to solve Multi-objective prob. from pyopt-sparse in OpenMDAO
  • How to get next/previous record number?
  • GridView Sorting works once only
  • 0x202A in filename: Why?
  • How do I rollback to a specific git commit
  • Python: how to group similar lists together in a list of lists?
  • How get height of the a view with gone visibility and height defined as wrap_content in xml?
  • Linking SubReports Without LinkChild/LinkMaster
  • Authorize attributes not working in MVC 4
  • Busy indicator not showing up in wpf window [duplicate]
  • Python/Django TangoWithDjango Models and Databases
  • Net Present Value in Excel for Grouped Recurring CF