asp.net mvc - Service Layer to Automatically identify database to use -


I am working on the asp.net MVC application.

The app is structured as follows: <

  • Data
  • Web MVC
  • Services - Business Rules
  • SQL database is using the data layer to use LinqToSql.

    When a user logs in to the application based on the user name, then I can do a lookup to see which organization they fall, depending on the organization, the database change is the same, if the user If the organization is 1, then it should use DB 01 or if User Organization is 2 then DB 02.

    Both users have common DB which they also use.

    My question is really, how can I automate the selection of the target database? I think this is to do with the layer of services. When starting the data class, I used to pass the target DB in the connection string.

    However for doing so, I will have to present an active user token in the form of a parameter for the service layer, that is, this address for the Org id / etc service.

    On the web project I am using IModelBinder to bind tokens it stores in session.

    Is there any good way to pass the immodelbander object at the service level or to use any other method.

    I want to pass these values ​​through the law standards. Since the question has been tagged dependency-injection (DI), suppose that DI is already in use and the Data Access Component (DAC) Controllers are being injected.

    As always with the AI, the key to presenting a abstract factory and the key to be able to isolate the injection dependency by business logic is the basic component.

    In your case, it may look like this to a lesser extent:

      Public interface IRPaFactoryFactor {Create IRPository (String Username); }  

    In those places where you had already injected your IRPGetry examples, you can now attach the IRAPGattery Factory and then userName to get the appropriate DAC You can use.


  • Comments

    Popular posts from this blog

    c# - How to capture HTTP packet with SharpPcap -

    jquery - SimpleModal Confirm fails to submit form -

    php - Multiple Select with Explode: only returns the word "Array" -