Ejemplo n.º 1
0
        protected virtual void ConfigureNHibernate()
        {
            var configuration = new Configuration()
                                .SetProperties(new Dictionary <string, string>
            {
                { Environment.Dialect, typeof(MsSql2005Dialect).AssemblyQualifiedName },
                { Environment.ProxyFactoryFactoryClass, typeof(ProxyFactoryFactory).AssemblyQualifiedName },
                { Environment.ConnectionString, RootContext.GetConnectionStringFor(TenantId) },
            });
            var customMapping = GetMappingFrom(Assembly);
            var added         = new HashSet <string>();

            foreach (var mapping in customMapping)
            {
                configuration.AddResource(mapping, Assembly);
                added.Add(GetEntityName(mapping));
            }
            var coreMapping = GetMappingFrom(typeof(AbstractBootStrapper).Assembly);

            foreach (var mapping in coreMapping)
            {
                if (added.Add(GetEntityName(mapping)) == false)
                {
                    continue;//already there
                }
                configuration.AddResource(mapping, typeof(AbstractBootStrapper).Assembly);
            }

            container.Kernel.AddComponentInstance <Configuration>(configuration);

            ISessionFactory sessionFactory = configuration.BuildSessionFactory();

            container.Kernel.AddComponentInstance <ISessionFactory>(sessionFactory);
        }