| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- using System.Linq;
- using System.Reflection;
- using Abp;
- using Abp.Collections.Extensions;
- using Abp.Configuration.Startup;
- using Abp.Dependency;
- using Abp.Localization;
- using Abp.Localization.Dictionaries;
- using Abp.Localization.Dictionaries.Xml;
- using Abp.Modules;
- using Abp.MultiTenancy;
- using Abp.Reflection;
- using Abp.Reflection.Extensions;
- using IwbZero.Authorization.Base.Roles;
- using IwbZero.Authorization.Base.SystemInfo;
- using IwbZero.Authorization.Base.Users;
- using IwbZero.MultiTenancy;
- using IwbZero.Zero.Configuration;
- namespace IwbZero
- {
- [DependsOn(typeof(AbpKernelModule))]
- public class IwbZeroModule : AbpModule
- {
- public override void PreInitialize()
- {
- Configuration.BackgroundJobs.IsJobExecutionEnabled = true;
- IocManager.RegisterIfNot<IIwbZeroEntityTypes, IwbZeroEntityTypes>(); //Registered on services.AddAbpIdentity() for Abp.ZeroCore.
- IocManager.Register<IRoleManagementConfig, RoleManagementConfig>();
- IocManager.Register<IUserManagementConfig, UserManagementConfig>();
- IocManager.Register<ILanguageManagementConfig, LanguageManagementConfig>();
- IocManager.Register<IIwbZeroConfig, IwbZeroConfig>();
- Configuration.ReplaceService<ITenantStore, TenantStore>(DependencyLifeStyle.Transient);
- Configuration.Settings.Providers.Add<IwbZeroSettingProvider>();
- foreach (var languageInfo in Configuration.Localization.Languages)
- {
- Configuration.Localization.Languages.Remove(languageInfo);
- }
- Configuration.Localization.Languages.Add(new LanguageInfo("zh-Hans", "简体中文", "cn", true));
- Configuration.Localization.Languages.Add(new LanguageInfo("en", "English", "us"));
- Configuration.Localization.Sources.Add(
- new DictionaryBasedLocalizationSource(
- IwbZeroConsts.LocalizationSourceName,
- new XmlEmbeddedFileLocalizationDictionaryProvider(
- typeof(IwbZeroModule).GetAssembly(), "IwbZero.Zero.Localization.Source"
- )));
- AddIgnoredTypes();
- }
- public override void Initialize()
- {
- FillMissingEntityTypes();
- IocManager.RegisterAssemblyByConvention(typeof(IwbZeroModule).GetAssembly());
- RegisterTenantCache();
- }
- private void AddIgnoredTypes()
- {
- var ignoredTypes = new[]
- {
- typeof(SysLog)
- };
- foreach (var ignoredType in ignoredTypes)
- {
- Configuration.EntityHistory.IgnoredTypes.AddIfNotContains(ignoredType);
- }
- }
- private void FillMissingEntityTypes()
- {
- using (var entityTypes = IocManager.ResolveAsDisposable<IIwbZeroEntityTypes>())
- {
- if (entityTypes.Object.User != null &&
- entityTypes.Object.Role != null &&
- entityTypes.Object.Tenant != null)
- {
- return;
- }
- using (var typeFinder = IocManager.ResolveAsDisposable<ITypeFinder>())
- {
- var types = typeFinder.Object.FindAll();
- entityTypes.Object.Tenant = types.FirstOrDefault(t => typeof(TenantBase).IsAssignableFrom(t) && !t.GetTypeInfo().IsAbstract);
- entityTypes.Object.Role = types.FirstOrDefault(t => typeof(RoleBase).IsAssignableFrom(t) && !t.GetTypeInfo().IsAbstract);
- entityTypes.Object.User = types.FirstOrDefault(t => typeof(UserBase).IsAssignableFrom(t) && !t.GetTypeInfo().IsAbstract);
- entityTypes.Object.Function = types.FirstOrDefault(t => typeof(SysFunctionBase).IsAssignableFrom(t) && !t.GetTypeInfo().IsAbstract);
- entityTypes.Object.State = types.FirstOrDefault(t => typeof(SysStateBase).IsAssignableFrom(t) && !t.GetTypeInfo().IsAbstract);
- entityTypes.Object.AttachFile = types.FirstOrDefault(t => typeof(SysAttachFileBase).IsAssignableFrom(t) && !t.GetTypeInfo().IsAbstract);
- entityTypes.Object.Help = types.FirstOrDefault(t => typeof(SysHelpBase).IsAssignableFrom(t) && !t.GetTypeInfo().IsAbstract);
- }
- }
- }
- private void RegisterTenantCache()
- {
- if (IocManager.IsRegistered<ITenantCache>())
- {
- return;
- }
- using (var entityTypes = IocManager.ResolveAsDisposable<IIwbZeroEntityTypes>())
- {
- var implType = typeof(TenantCache<,>)
- .MakeGenericType(entityTypes.Object.Tenant, entityTypes.Object.User);
- IocManager.Register(typeof(ITenantCache), implType, DependencyLifeStyle.Transient);
- }
- }
- }
- }
|