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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T13:54:12+00:00 2026-05-16T13:54:12+00:00

Starting with some code: sessionFactory = Fluently.Configure(cfg) .Mappings(m => { List<Assembly> allAssemblies = new

  • 0

Starting with some code:

sessionFactory = Fluently.Configure(cfg)
                .Mappings(m => 
                {
                    List<Assembly> allAssemblies = new List<Assembly>();
                    string path = Assembly.GetExecutingAssembly().Location;
                    foreach (string dll in Directory.GetFiles(path, "*.dll"))
                    {
                        m.FluentMappings.AddFromAssembly(Assembly.LoadFile(dll));
                    }
                })
                .BuildSessionFactory();

I’m very new to both nhibernate and fluent nhibernate. The bit of code above looks like it should work, but to me it looks really ugly. Is there a neater way?

One problem I have is that the code that calls the above code is in a core assembly and is unable to make reference to some of the assemblies that need mapping as their assemblies reference the core assembly. So I can’t just use a few calls to AddFromAssemblyOf<T>.

Is there a cleaner way to do 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-05-16T13:54:13+00:00Added an answer on May 16, 2026 at 1:54 pm

    You could create a custom configuration node to put in your config files.

    You would have something like the following:

    <configSections>
        <section name="fluentConfigurationsSection" type="MyCoreAssembly.FluentConfigurationsSection, MyCoreAssembly"/>
    </configSections>
    
    <fluentConfigurationsSection>
        <fluentConfigurations>
          <clear />
          <add name="Assembly1" assembly="MyAssemblyNotReferencedByCoreAssembly.Mapping.Fluent"
          <add name="Assembly2" assembly="AnotherAssemblyNotReferencedByCoreAssembly.Mapping.Fluent"
          <add name="Assembly3" assembly="OneMoreAssemblyNotReferencedByCoreAssembly.Mapping.Fluent"
        </fluentConfigurations>
    </fluentConfigurationsSection>
    

    Then your code could be changed to something like:

    sessionFactory = Fluently.Configure(cfg)
                .Mappings(m => 
                {
                    foreach(var config in MethodToGetFluentConfigSectionItems())
                    {
                        //load each assembly in config file
                        m.FluentMappings.AddFromAssembly(Assembly.Load(config.Assembly); 
                    }
                })
                .BuildSessionFactory();
    

    To create the custom config section you could see here how to do it.

    Hope this helps.

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

Sidebar

Related Questions

I am in a project where we are starting refactoring some massive code base.
I have some code for starting a thread on the .NET CF 2.0: ThreadStart
I'm just starting to try out phpunit on some existing code. The naming convention
I have some old python code that uses the pywin32 extensions. Starting out with
Starting recently, some of my new web pages (XHTML 1.1) are setup to do
I'm just starting to design some embedded devices, and am looking for resources. What
I am just starting with coding some JSP, which I find isn't all that
I have been starting to write some reasonably large and or confusing MySQL queries
I am just starting with C++ and got some problems in understanding how the
I've done some Python but have just now starting to use Ruby I could

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.