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

  • Home
  • SEARCH
  • 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 6002949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:03:04+00:00 2026-05-23T01:03:04+00:00

I have three SQL Server databases that a single application retrieves data from. I

  • 0

I have three SQL Server databases that a single application retrieves data from. I am using NHibernate to retrieve data from the different databases. I have things set up so that each database has its own repository and class mappings in its own assembly. In my castle.config file I have the database connections setup using the Castle NHibernate Facility:

<?xml version="1.0" encoding="utf-8" ?>
<castle>
  <facilities>
    <facility id="factorysupport" type="Castle.Facilities.FactorySupport.FactorySupportFacility, Castle.Windsor" />
    <facility id="nhibernate" isWeb="false" type="Castle.Facilities.NHibernateIntegration.NHibernateFacility, Castle.Facilities.NHibernateIntegration">
      <factory id="databaseone.factory" alias="databaseone">
        <settings>
            <!--Settings Here -->
        </settings>
        <assemblies>
           <assembly>DAL.DatabaseOne</assembly>
        </assemblies>
      </factory>
      <factory id="databasetwo.factory" alias="databasetwo">
        <settings>
          <!--Settings Here -->
        </settings>
        <assemblies>
          <assembly>DAL.DatabaseTwo</assembly>
        </assemblies>
      </factory>
      <factory id="databasethree.factory" alias="databasethree">
        <settings>
            <!--Settings Here -->
        </settings>
        <assemblies>
             <assembly>DAL.DatabaseThree</assembly>
        </assemblies>
      </factory>
    </facility>
  </facilities>
</castle>

All of my repositories have a constructor that take an ISessionFactory as the parameter:

public MyRepository<T> : IRepository<T>
{
   public MyRepository(ISessionFactory factory)
   {
        //Do stuff here
   }
 }

I have an installer class where I would like to define the various repositories:

//In install method of IWindsorInstaller
container.register(Component.For(typeof(IRepository<>)).ImplementedBy(typeof(MyRepository<>));

Using one database things work fine. When I add the second database to the mix, the same ISessionFactory is injected into all of the repositories. My question is what is the best way to handle this? I could manually specify which ISessionFactory should be injected into which Repository<> but I cannot seem to find documentation on this. The best way would be if I could say something like: For all class mappings in assembly DAL.DatabaseOne, always inject the ISessionFactory corresponding to databaseone.factory; and for all class mappings in assembly DAL.DatabaseTwo, always inject the ISessionFactory corresponding to databasetwo.factory.

Thoughts or suggestions?

  • 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-23T01:03:05+00:00Added an answer on May 23, 2026 at 1:03 am

    This is explained in this post by Fabio Maulo toward the end under the heading ‘Configuring your DAOs/Repository for multiple DB’.

    He maps the factory individually for each domain class but you could also use reflection on each of the domain assemblies in your case to register the appropriate factory.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application that needs to join tables from multiple databases into a
I have a table in SQL Server 2005 which has three columns: id (int),
I have a table in SQL server that has the normal tree structure of
I have a VB.NET application with a connection to an SQL Server 2003. On
i am used to SQL Server and SQL enterprise studio when using databases in
I have a table named t_Student in Microsoft SQL Server 2005 database. In that
Is there a setting in SQL Server to have null = null evaluate to
Is there a connection limit on Sql Server 2005 Developers Edition. We have many
Have you ever seen any of there error messages? -- SQL Server 2000 Could
Is there a way to have an application access a SQL Compact database file

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.