Beispiel #1
0
        public override void PreInitialize()
        {
            IocManager.Register <IShaNHibernateModuleConfiguration, ShaNHibernateModuleConfiguration>();
            Configuration.ReplaceService <IUnitOfWorkFilterExecuter, NhUnitOfWorkFilterExecuter>(DependencyLifeStyle.Transient);
            IocManager.IocContainer.Register(Component.For <IInterceptor>().ImplementedBy <SheshaNHibernateInterceptor>().LifestyleTransient());

            Configuration.Modules.AbpAspNetCore().CreateControllersForAppServices(
                this.GetType().Assembly,
                moduleName: "Shesha",
                useConventionalHttpVerbs: true);

            if (!SkipDbContextRegistration)
            {
                _nhConfig = Configuration.Modules.ShaNHibernate().NhConfiguration
                            .DataBaseIntegration(db =>
                {
                    db.ConnectionString = !string.IsNullOrWhiteSpace(ConnectionString)
                            ? ConnectionString
                            : NHibernateUtilities.ConnectionString;

                    db.Dialect <MsSql2012Dialect>();
                    db.Driver <Sql2008ClientDriver>();
                    db.Timeout = 150;

                    /*
                     * db.Timeout = string.IsNullOrEmpty(ConfigurationManager.AppSettings["SqlTimeoutInSeconds"])
                     *  ? (byte)150
                     *  : (byte)int.Parse(ConfigurationManager.AppSettings["SqlTimeoutInSeconds"]);
                     */

                    db.LogFormattedSql = true;
                })
                            .SetProperty("hbm2ddl.keywords", "auto-quote")
                            .CurrentSessionContext <UnitOfWorkSessionContext>();

                // register filters
                _nhConfig.AddFilterDefinition(SoftDeleteFilter.GetDefinition());
                _nhConfig.AddFilterDefinition(MayHaveTenantFilter.GetDefinition());
                _nhConfig.AddFilterDefinition(MustHaveTenantFilter.GetDefinition());

                var conventions       = new Conventions();
                var mappingAssemblies = new Dictionary <Assembly, string>
                {
                    { typeof(UserToken).Assembly, "Abp" },
                    { typeof(UserLogin).Assembly, "Abp" }
                };
                foreach (var item in mappingAssemblies)
                {
                    conventions.AddAssembly(item.Key, item.Value);
                }

                var assembliesWithEntities = _assembleFinder.GetAllAssemblies()
                                             .Distinct(new AssemblyFullNameComparer())
                                             .Where(a => !a.IsDynamic &&
                                                    a.GetTypes().Any(t => MappingHelper.IsEntity(t))
                                                    )
                                             .ToList();
                foreach (var assembly in assembliesWithEntities)
                {
                    if (!conventions.AssemblyAdded(assembly))
                    {
                        conventions.AddAssembly(assembly, assembly.GetCustomAttribute <TablePrefixAttribute>()?.Prefix);
                    }
                }

                conventions.Compile(_nhConfig);
            }
        }