public static ISessionFactory CreateSessionFactory()
        {
            var nhConfiguration = new Configuration();

            var configPath = ApplicationConfiguration.NHibernate.ConfigurationFilePath;
            if (configPath != null)
            {
                // used to allow visual studio unit tests
                nhConfiguration.Configure(configPath);
            }
            else
            {
                nhConfiguration.Configure();
            }
            //return configuration.BuildSessionFactory();

            IAutomappingConfiguration fluentConfiguration = ApplicationConfiguration.Fluent.MappingConfigurationInstance;
            if (fluentConfiguration == null) {
                fluentConfiguration = new DefaultAutomappingConfiguration();
            }

            var assembly = ApplicationConfiguration.DomainAssembly;

			var autoMap = AutoMap.Assembly(assembly, fluentConfiguration);

			var overrideAssembly = ApplicationConfiguration.Fluent.OverrideAssembly;
			if (overrideAssembly != null) {
				autoMap.UseOverridesFromAssembly(overrideAssembly);
			}

            autoMap.Conventions.Add(
                DefaultCascade.SaveUpdate(),
                DefaultLazy.Always(),
                new ColumnNullabilityConvention(),
                new ForeignKeyConstraintNameConvention(),
                new StringColumnLengthConvention(),
                new EnumConvention(),
                ForeignKey.EndsWith("_ID"),
                ConventionBuilder.Reference.Always(x => x.Not.Nullable()),
                ConventionBuilder.Reference.Always(x => x.Cascade.None()),
                ConventionBuilder.HasMany.Always(x => x.Inverse())
            );

            var sessionFactory = Fluently.Configure(nhConfiguration)
                .Mappings(m => m.AutoMappings.Add(autoMap))
				.BuildSessionFactory();

            return sessionFactory;
        }
 public static void Initialize(System.Reflection.Assembly domainAssembly, System.Reflection.Assembly infrastructureAssembly, DefaultAutomappingConfiguration mappingConfiguration, IInversionOfControlMapper inversionOfControlMapper)
 {
     ApplicationManager.Initialize(new ApplicationConfiguration
     {
         DomainAssembly = domainAssembly,
         Fluent = new ApplicationConfiguration.FluentConfiguration { OverrideAssembly = infrastructureAssembly, MappingConfigurationInstance = mappingConfiguration },
         InversionOfControl = new ApplicationConfiguration.InversionOfControlConfiguration { MapperInstance = inversionOfControlMapper }
     });
 }