Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7000061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:37:20+00:00 2026-05-27T20:37:20+00:00

I have a case where each customer has his own DB – What i

  • 0

I have a case where each customer has his own DB – What i would like to do is for this to happen automatically eg when Autofac creates the controller it looks up the clientId and then gets the connection string

The following gets the string

public class ModuleContextProvider : IModuleContextProvider
{
    IModuleContext context;



    public IModuleContext GetContext(int moduleId)
    {
        if ( context == null) 
        {

            //get module.
            var rep = DependencyResolver.Current.GetService<IModuleRepository>();
            var module = rep.GetById(moduleId);
            context = GetContext(module);
        }

        return context;

    }

    public IModuleContext GetContext(Model.Module module)
    {


        if ( context == null) 
        {

            //get module.
            var rep = DependencyResolver.Current.GetService<IModuleRepository>();
            context = new ModuleContext(module.DBConnection); 
            if ( context == null) 
                throw new InvalidOperationException("Could nto create DB COntext" );
        }

                 return context;
    }
}

but how do i get it into the Controllers so everyone does not need to worry about it each time , i have the following but obviously to create the repositry i need the context.

    public CategoryController(ICommandBus commandBus, ICategoryRepository categoryRepository)
    {
        this.commandBus = commandBus;
        this.categoryRepository = categoryRepository;
    }  

Is it possible to use a ROute eg //Controller/ModuleId/Method and then somehow get this from the Url ?

Thanks in advance for any help.

Edit: The real issue here I think is how to keep pushing the connection string around ( in this case in the form of the module) .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T20:37:21+00:00Added an answer on May 27, 2026 at 8:37 pm

    If anyone needs this ..

    I stored it in the cookie and retrieve in the controller as follows

        IModuleWorldRepository moduleWorldRepository;
    
        protected override void Initialize(System.Web.Routing.RequestContext requestContext)
        {
            base.Initialize(requestContext);
            moduleWorldRepository = GetModuleWorldRepository();
    
        }
    
        IModuleWorldRepository GetModuleWorldRepository()
        {
    
            UserRunTimeInfo user = (UserRunTimeInfo)User.Identity;
            var context = contextProvider.GetContext(user.CurrentModuleId);
            return new ModuleWorldRepository(context);
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to have two EntityManagerFactories ( org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean in this case), with each of
This is a simplified version of a query I have. Say for each customer
My company has a large customer that has many regions/sites/offices. Each location can have
I have this case <WrapPanel> <CheckBox>Really long name</CheckBox> <CheckBox>Short</CheckBox> <CheckBox>Longer again</CheckBox> <CheckBox>Foo</CheckBox> <Slider MinWidth=200
I'm working on a web-based business application where each customer will need to have
I have two services, Customer service and Product service. They are independent and each
Let say that for each customer you have to dynamically create a database when
If you have a customer class with 85 properties and you assign each property
Here is a simple example: Assume I have a customer table that has a
I have a case where a 3rd party ad is bleeding through my modal

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.