0

By default, the solution generated from Sharp Architecture's templify package configures NHibernate using an NHibernate.config file in the {SolutionName}.Web project. I would like to replace it with a fluent configuration of my own and still have the rest of Sharp Architecture work correctly.

Any help will be much appreciated. :)

Solution: Here's how I got it to work:

IPersistenceConfigurer configurer = OracleClientConfiguration.Oracle10
    .AdoNetBatchSize(500)
    .ShowSql()
    .ConnectionString(c => c.FromConnectionStringWithKey("NHibernate.Localhost"))
    .DefaultSchema("MySchema")
    .ProxyFactoryFactory("NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")
    .UseReflectionOptimizer();

NHibernateSession.Init(
    webSessionStorage,
    new string[] { Server.MapPath("~/bin/MyProject.Data.dll") },
    new AutoPersistenceModelGenerator().Generate(),
    null,
    null,
    null,
    configurer);
rebelliard
  • 9,592
  • 6
  • 47
  • 80

2 Answers2

0

Very old post. I'll leave it here in case someone else is interested. On SharpArch 1.9.6.0 you can add two methods to NHibernateSession.cs. This will let you pass-in a FluentConfiguration object.

    public static FluentConfiguration Init(ISessionStorage storage, FluentConfiguration fluentConfiguration)
    {
        InitStorage(storage);
        try
        {
            return AddConfiguration(DefaultFactoryKey, fluentConfiguration);
        }
        catch
        {
            // If this NHibernate config throws an exception, null the Storage reference so 
            // the config can be corrected without having to restart the web application.
            Storage = null;
            throw;
        }
    }

    private static FluentConfiguration AddConfiguration(string defaultFactoryKey, FluentConfiguration fluentConfiguration)
    {
        var sessionFactory = fluentConfiguration.BuildSessionFactory();
        Check.Require(!sessionFactories.ContainsKey(defaultFactoryKey),
            "A session factory has already been configured with the key of " + defaultFactoryKey);

        sessionFactories.Add(defaultFactoryKey, sessionFactory);

        return fluentConfiguration;
    }
Yosoyadri
  • 551
  • 5
  • 8
0

iirc the NhibernateSession class that is used to configure nhibernate has a bunch of overloads one of them giving you the ability to configure it via code.

maciek
  • 661
  • 4
  • 10
  • I don't see where I would send a Fluent configuration variable, no. – rebelliard Apr 18 '11 at 20:27
  • hi -sorry you are correct by default from what I see you can only pass a dictionary of configuration properties but in the end internally that class uses the fluent configuration to return a session factory. you'd probably have to modify the class to get it to accept a fluent config. – maciek Apr 19 '11 at 00:48
  • Thanks, I got it to work with a bunch of completely unnatural nulls. :D – rebelliard Apr 19 '11 at 13:15