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 8838221
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:56:10+00:00 2026-06-14T09:56:10+00:00

I am working on setting up a multi-tenant, seperate database application and have made

  • 0

I am working on setting up a multi-tenant, seperate database application and have made some good progress from reading this post below on stackoverflow.

Multitenancy with Fluent nHibernate and Ninject. One Database per Tenant

I see two sessions being setup. One is the ‘master’ session that will be used to get the tenant information and then the tenant session which is specific to the subdomain. I have the app switching nicely to the specified database based on domain and have questions on how to setup the ‘master’ database session and how to use it.

I tried registering a new session specifically for the master session be get an error regarding having already registered an ISession.

I’m new to nHibernate and not sure the best route to take on this.

NinjectWebCommon.cs

kernel.Bind<WebApplication1.ISessionSource>().To<NHibernateTenantSessionSource>().InSingletonScope();
kernel.Bind<ISession>().ToMethod(c => c.Kernel.Get<WebApplication1.ISessionSource>().CreateSession());
kernel.Bind<ITenantAccessor>().To<DefaultTenantAccessor>();

ITenantAccessor.cs

 public Tenant GetCurrentTenant()
    {
      var host = HttpContext.Current.Request.Url != null ? HttpContext.Current.Request.Url.Host : string.Empty;

      var pattern = ConfigurationManager.AppSettings["UrlRegex"];
      var regex = new Regex(pattern);
      var match = regex.Match(host);

      var subdomain = match.Success ? match.Groups[1].Value.ToLowerInvariant() : string.Empty;
      Tenant tenant = null;

      if (subdomain != null)
      {
        // Get Tenant info from Master DB.
        // Look up needs to be cached
        DomainModel.Master.Tenants tenantInfo;

        using (ISession session = new NHibernateMasterSessionSource().CreateSession())
        {
            tenantInfo = session.CreateCriteria<DomainModel.Master.Tenants>()
                .Add(Restrictions.Eq("SubDomain", subdomain))
                .UniqueResult<WebApplication1.DomainModel.Master.Tenants>();
        }

        var connectionString = string.Format(ConfigurationManager.AppSettings["TenanatsDataConnectionStringFormat"], 
            tenantInfo.DbName, tenantInfo.DbUsername, tenantInfo.DbPassword);

        tenant = new Tenant();
        tenant.Name = subdomain;
        tenant.ConnectionString = connectionString;
      }

      return tenant;
    }

Thanks for you time on this.

  • 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-06-14T09:56:11+00:00Added an answer on June 14, 2026 at 9:56 am

    Add another session binding and add some condition. E.g.

    kernel
        .Bind<ISession>()
        .ToMethod(c => c.Kernel.Get<NHibernateMasterSessionSource>().CreateSession())
        .WhenInjectedInto<TenantEvaluationService>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on setting up log4net in a multi-tiered application. I have most of
I am working on a multi-threaded application. This application started out as a single
I'm working on setting up NHibernate for a project and I have a few
I'm working on an app (Written in C#) that have a setting to run
I am working on an Java application, and I'm setting the LookAndFeel. Everything of
I am working on setting up a centralized repository to store enterprise architect (from
I am working on setting up JqGrid with Grails and have in-line editing working.
I'm working on setting up a simple multi-tier Rails 3.1 setup -- web apps
This is from a Cognos report, it has an interactive, multi-valued prompt (P_prompt_param). The
I'm working on a relatively simple iPhone application that has a multi-round Timer with

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.