public static void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { var repositoryType = dbContextType.Assembly.GetTypes().Where(type => !string.IsNullOrEmpty(type.Namespace)) .Where(type => type.BaseType != null && type.BaseType.IsGenericType && (type.BaseType.GetGenericTypeDefinition() == typeof(IRepository<>) || type.BaseType.GetGenericTypeDefinition() == typeof(IRepository<,>) || type.BaseType.GetGenericTypeDefinition() == typeof(EfRepositoryBase<,>) || type.BaseType.GetGenericTypeDefinition() == typeof(EfRepositoryBase<,,>))); foreach (var entityType in dbContextType.GetEntityTypes())//从dataset中获取所有的实体 { foreach (var interfaceType in entityType.GetInterfaces())//获取所有实体实现的接口 { if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IEntity<>)) { var primaryKeyType = interfaceType.GenericTypeArguments[0];//获取所有的实体的主键 foreach (var maprepositoryType in repositoryType) { if (!iocManager.IsRegistered(maprepositoryType)) { var implType = maprepositoryType.GetGenericArguments().Length == 2 ? maprepositoryType.MakeGenericType(entityType, primaryKeyType) : maprepositoryType.MakeGenericType(dbContextType, entityType, primaryKeyType); iocManager.Register( maprepositoryType, implType, DependencyLifeStyle.Transient ); } } } } } }
public static void Initialize(IIocManager manager,List<Assembly> assemblys) { assemblys.ForEach(m => { ////多实例 //manager.IocContainer.Register( // Classes.FromAssembly(m) // .IncludeNonPublicTypes() // .BasedOn<IMultipleDependency>() // .WithService.Self() // .WithService.DefaultInterfaces() // .LifestyleTransient() // ); ////单例 //manager.IocContainer.Register( // Classes.FromAssembly(m) // .IncludeNonPublicTypes() // .BasedOn<ISingleDependency>() // .WithService.Self() // .WithService.DefaultInterfaces() // .LifestyleSingleton() // ); ////拦截器 //manager.IocContainer.Register( // Classes.FromAssembly(m) // .IncludeNonPublicTypes() // .BasedOn<IInterceptor>() // .WithService.Self() // .LifestyleTransient() // ); Registrants.ForEach(r => r(m)); }); }
public DefaultModuleManager(IIocManager iocManager, IModuleFinder moduleFinder, IConfigurationManager configurationManager) { _modules = new ModuleCollection(); _iocManager = iocManager; _moduleFinder = moduleFinder; _configurationManager = configurationManager; }
public AbpNHibernateInterceptor(IIocManager iocManager) { _iocManager = iocManager; _abpSession = new Lazy<IAbpSession>( () => _iocManager.IsRegistered(typeof(IAbpSession)) ? _iocManager.Resolve<IAbpSession>() : NullAbpSession.Instance, isThreadSafe: true ); _guidGenerator = new Lazy<IGuidGenerator>( () => _iocManager.IsRegistered(typeof(IGuidGenerator)) ? _iocManager.Resolve<IGuidGenerator>() : SequentialGuidGenerator.Instance, isThreadSafe: true ); _eventBus = new Lazy<IEventBus>( () => _iocManager.IsRegistered(typeof(IEventBus)) ? _iocManager.Resolve<IEventBus>() : NullEventBus.Instance, isThreadSafe: true ); }
/// <summary> /// Constructor. /// </summary> public PermissionManager(IIocManager iocManager, IAuthorizationConfiguration authorizationConfiguration) { _iocManager = iocManager; _authorizationConfiguration = authorizationConfiguration; AbpSession = NullAbpSession.Instance; }
public static void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { var autoRepositoryAttr = dbContextType.GetSingleAttributeOrNull<AutoRepositoryTypesAttribute>(); if (autoRepositoryAttr == null) { autoRepositoryAttr = AutoRepositoryTypesAttribute.Default; } foreach (var entityType in dbContextType.GetEntityTypes()) { var genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityType); if (!iocManager.IsRegistered(genericRepositoryType)) { var implType = autoRepositoryAttr.RepositoryImplementation.GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(dbContextType, entityType); iocManager.Register( genericRepositoryType, implType, DependencyLifeStyle.Multiple ); } } }
public AbpModuleManager(IIocManager iocManager, IModuleFinder moduleFinder) { _modules = new AbpModuleCollection(); _iocManager = iocManager; _moduleFinder = moduleFinder; Logger = NullLogger.Instance; }
public LanguageManagementConfig(IIocManager iocManager, IAbpStartupConfiguration configuration) { _iocManager = iocManager; _configuration = configuration; Logger = NullLogger.Instance; }
private static void Test_Way_2(IIocManager iocManager) { using (var tester = iocManager.ResolveAsDisposable<Tester>()) { tester.Object.Test(); } }
public static void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { foreach (var entityType in dbContextType.GetEntityTypes()) { foreach (var interfaceType in entityType.GetInterfaces()) { if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IEntity<>)) { var primaryKeyType = interfaceType.GenericTypeArguments[0]; if (primaryKeyType == typeof(Guid)) { var genericRepositoryType = typeof(IRepository<>).MakeGenericType(entityType); if (!iocManager.IsRegistered(genericRepositoryType)) { iocManager.Register( genericRepositoryType, typeof(EfRepositoryBase<,>).MakeGenericType(dbContextType, entityType), DependencyLifeStyle.Transient ); } } var genericRepositoryTypeWithPrimaryKey = typeof(IRepository<,>).MakeGenericType(entityType, primaryKeyType); if (!iocManager.IsRegistered(genericRepositoryTypeWithPrimaryKey)) { iocManager.Register( genericRepositoryTypeWithPrimaryKey, typeof(EfRepositoryBase<,,>).MakeGenericType(dbContextType, entityType, primaryKeyType), DependencyLifeStyle.Transient ); } } } } }
public AbpModuleManager(IIocManager iocManager, IAbpPlugInManager abpPlugInManager) { _modules = new AbpModuleCollection(); _iocManager = iocManager; _abpPlugInManager = abpPlugInManager; Logger = NullLogger.Instance; }
private static void Test_Way_3(IIocManager iocManager) { iocManager.Using<Tester>(tester => { tester.Test(); }); }
private static void Test_Way_1(IIocManager iocManager) { var tester = iocManager.Resolve<Tester>(); tester.Test(); iocManager.Release(tester); }
public UnitOfWorkManager( IIocManager iocManager, IUnitOfWorkProvider currentUnitOfWorkProvider, IUnitOfWorkDefaultOptions defaultOptions) { _iocManager = iocManager; _currentUnitOfWorkProvider = currentUnitOfWorkProvider; _defaultOptions = defaultOptions; }
public AbpNHibernateInterceptor(IIocManager iocManager) { _iocManager = iocManager; _abpSession = new Lazy<IAbpSession>( () => _iocManager.IsRegistered(typeof(IAbpSession)) ? _iocManager.Resolve<IAbpSession>() : NullAbpSession.Instance ); }
/// <summary> /// Constructor. /// </summary> public DynamicAuthorizationManager( IIocManager iocManager, IPermissionDefinitionContext permissionContext, IAuthorizationConfiguration authorizationConfiguration ) { _iocManager = iocManager; _permissionContext = permissionContext; _authorizationConfiguration = authorizationConfiguration; }
public static void RegisterForService(IIocManager iocManager) { var typetoMap = Assembly.GetExecutingAssembly().GetTypes() .Where(type => !string.IsNullOrEmpty(type.Namespace)) .Where(type => type.BaseType != null && type.BaseType.IsInterface && type.BaseType == typeof(IApplicationService)); foreach (var mapType in typetoMap) { iocManager.Register(mapType, DependencyLifeStyle.Transient); } }
/// <summary> /// Constructor. /// </summary> public PermissionManager(IIocManager iocManager, IAuthorizationConfiguration authorizationConfiguration) { PermissionGrantStore = NullPermissionGrantStore.Instance; Logger = NullLogger.Instance; _iocManager = iocManager; _authorizationConfiguration = authorizationConfiguration; _rootGroups = new Dictionary<string, PermissionGroup>(); _permissions = new PermissionDictionary(); }
static ServiceManager() { ServiceContext = new ServiceContext(); ServiceContext.Scheduler = null; ServiceContext.WcfHost = null; ServiceContext.ProgressInfoManager = ProgressInfoManager.Instance; iocManager = IocManager.Instance; Initialize(); }
public static void Initialize(IIocManager iocManager) { var auditingConfiguration = iocManager.Resolve<IAuditingConfiguration>(); iocManager.IocContainer.Kernel.ComponentRegistered += (key, handler) => { if (ShouldIntercept(auditingConfiguration, handler.ComponentModel.Implementation)) { handler.ComponentModel.Interceptors.Add(new InterceptorReference(typeof(AuditingInterceptor))); } }; }
public static void Initialize(IIocManager iocManager) { _auditingConfiguration = iocManager.Resolve<IAuditingConfiguration>(); if (!_auditingConfiguration.IsEnabled) { return; } iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered; }
/// <summary> /// Constructor. /// </summary> public PermissionManager( IIocManager iocManager, IAuthorizationConfiguration authorizationConfiguration, FeatureDependencyContext featureDependencyContext ) { _iocManager = iocManager; _authorizationConfiguration = authorizationConfiguration; _featureDependencyContext = featureDependencyContext; AbpSession = NullAbpSession.Instance; }
public static void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { //获取已经标记的 "AutoRepositoryTypesAttribute" 属性 var autoRepositoryAttr = dbContextType.GetSingleAttributeOrNull<AutoRepositoryTypesAttribute>(); //没有标记"AutoRepositoryTypesAttribute"属性的"DbContext"采用默认AutoRepositoryTypesAttribute属性 if (autoRepositoryAttr == null) { autoRepositoryAttr = AutoRepositoryTypesAttribute.Default; } //获取DbSet或者IDbSet属性 foreach (var entityType in dbContextType.GetEntityTypes()) { foreach (var interfaceType in entityType.GetInterfaces()) { if (interfaceType.IsGenericType && interfaceType.GetGenericTypeDefinition() == typeof(IEntity<>)) { var primaryKeyType = interfaceType.GenericTypeArguments[0]; if (primaryKeyType == typeof(int)) { var genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityType); if (!iocManager.IsRegistered(genericRepositoryType)) { var implType = autoRepositoryAttr.RepositoryImplementation.GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(dbContextType, entityType); iocManager.Register( genericRepositoryType, implType, DependencyLifeStyle.Transient ); } } var genericRepositoryTypeWithPrimaryKey = autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey.MakeGenericType(entityType, primaryKeyType); if (!iocManager.IsRegistered(genericRepositoryTypeWithPrimaryKey)) { var implType = autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(dbContextType, entityType, primaryKeyType); iocManager.Register( genericRepositoryTypeWithPrimaryKey, implType, DependencyLifeStyle.Transient ); } } } } }
public static void Initialize(IIocManager manager, List<Assembly> assemblys) { assemblys.ForEach(m => { // controller manager.IocContainer.Register( Classes.FromAssembly(m) .IncludeNonPublicTypes() .BasedOn<System.Web.Mvc.Controller>() .WithService.Self() .WithService.DefaultInterfaces() .LifestyleTransient() ); }); }
public BdfNHibernateInterceptor(IIocManager iocManager) { _iocManager = iocManager; _BdfSession = new Lazy<IBdfSession>( () => _iocManager.IsRegistered(typeof(IBdfSession)) ? _iocManager.Resolve<IBdfSession>() : NullBdfSession.Instance ); EntityChangedEventHelper = _iocManager.IsRegistered(typeof (IEntityChangedEventHelper)) ? _iocManager.Resolve<IEntityChangedEventHelper>() : NullEntityChangedEventHelper.Instance; }
//核心部分的注册 public void Init(IIocManager iocManager) { var container = iocManager.Container; var builder = new ContainerBuilder(); var assemblies = AppDomain.CurrentDomain.GetAssemblies(); //所有注册器 var finder = new WebAppTypeFinder(); var allRegistrars = finder.FindClassOfType(typeof(IDependencyRegistrar)); foreach (var registrar in allRegistrars) (Activator.CreateInstance(registrar) as IDependencyRegistrar).Register(builder); //织入点配置 var proxyOption = new ProxyGenerationOptions() { Selector = new InterceptorSelector() }; //注册所有拦截器 builder.RegisterAssemblyTypes(assemblies) .Where(type => type.IsAssignableTo<Castle.DynamicProxy.IInterceptor>()); //注册单例 builder.RegisterAssemblyTypes(assemblies) .EnableInterfaceInterceptors(proxyOption) .Where(type => type.IsAssignableTo<ISingletonDependency>()) .AsImplementedInterfaces() //.Named<ISingletonDependency>(type => type.Name) .SingleInstance(); //注册瞬态 builder.RegisterAssemblyTypes(assemblies) .Where(type => type.IsAssignableTo<ITransientDependency>()) .AsImplementedInterfaces() .InstancePerLifetimeScope() .EnableInterfaceInterceptors(proxyOption); builder.RegisterType<DefaultEventBus>().Named<IEventBus>(BusEnum.DefaultBus.GetName()); builder.RegisterType<MsmqEventBus>().Named<IEventBus>(BusEnum.MsmqBus.GetName()); builder.RegisterInstance<IContainer>(container); builder.RegisterInstance<IIocResolver>(iocManager); builder.Update(container); }
public static void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { var autoRepositoryAttr = dbContextType.GetSingleAttributeOrNull<AutoRepositoryTypesAttribute>() ?? AutoRepositoryTypesAttribute.Default; foreach (var entityType in dbContextType.GetEntityTypes()) { foreach (var interfaceType in entityType.GetInterfaces()) { if (!interfaceType.IsGenericType || interfaceType.GetGenericTypeDefinition() != typeof (IEntity<>)) continue; var primaryKeyType = interfaceType.GenericTypeArguments[0]; if (primaryKeyType == typeof(int)) { var genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityType); if (!iocManager.IsRegistered(genericRepositoryType)) { var implType = autoRepositoryAttr.RepositoryImplementation.GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(dbContextType, entityType); iocManager.Register( genericRepositoryType, implType, DependencyLifeStyle.Transient ); } } var genericRepositoryTypeWithPrimaryKey = autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey.MakeGenericType(entityType, primaryKeyType); if (!iocManager.IsRegistered(genericRepositoryTypeWithPrimaryKey)) { var implType = autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(dbContextType, entityType, primaryKeyType); iocManager.Register( genericRepositoryTypeWithPrimaryKey, implType, DependencyLifeStyle.Transient ); } } } }
/// <summary> /// 注册数据上下文 /// </summary> /// <param name="dbContextType">数据上下文类型</param> /// <param name="iocManager">IOC管理</param> public static void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { //获取AutoRepositoryTypesAttribute自动仓储类型自定义属性的类型 var autoRepositoryAttr = dbContextType.GetSingleAttributeOrNull<AutoRepositoryTypesAttribute>(); if (autoRepositoryAttr == null) { autoRepositoryAttr = AutoRepositoryTypesAttribute.Default; } foreach (var entityType in dbContextType.GetEntityTypes()) { var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityType); if (primaryKeyType == typeof(int)) { var genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityType); if (!iocManager.IsRegistered(genericRepositoryType)) { var implType = autoRepositoryAttr.RepositoryImplementation.GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(dbContextType, entityType); iocManager.Register( genericRepositoryType, implType, DependencyLifeStyle.Transient ); } } var genericRepositoryTypeWithPrimaryKey = autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey.MakeGenericType(entityType, primaryKeyType); if (!iocManager.IsRegistered(genericRepositoryTypeWithPrimaryKey)) { var implType = autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(dbContextType, entityType, primaryKeyType); iocManager.Register( genericRepositoryTypeWithPrimaryKey, implType, DependencyLifeStyle.Transient ); } } }
public static void Register(IIocManager iocManager) { RegisterIdentity(iocManager); var builder = new DbContextOptionsBuilder <ProjectDbContext>(); var inMemorySqlite = new SqliteConnection("Data Source=:memory:"); builder.UseSqlite(inMemorySqlite); iocManager.IocContainer.Register( Component .For <DbContextOptions <ProjectDbContext> >() .Instance(builder.Options) .LifestyleSingleton() ); inMemorySqlite.Open(); new ProjectDbContext(builder.Options).Database.EnsureCreated(); }
private void RegisterGenericRepositories(IIocManager manager) { var dbContextTypes = TypeFinder.Find(type => type.IsPublic && !type.IsAbstract && type.IsClass && typeof(MongoDbContext).IsAssignableFrom(type) ); if (dbContextTypes.Count() <= 0) { return; // 没有 mongodbContext } //dbContextTypes.ToList().ForEach(m => IocManager.Register(m)); foreach (var dbContextType in dbContextTypes) { MongoDbGenericRepositoryRegistrar.RegisterForDbContext(dbContextType, manager); } }
private void RegisterGenericRepositories(IIocManager manager) { var dbContextTypes = TypeFinder.Find(type => type.IsPublic && !type.IsAbstract && type.IsClass && typeof(DbContext).IsAssignableFrom(type) ); if (dbContextTypes.Count() <= 0) { throw new Exception("No class found derived from DbContext."); } dbContextTypes.ToList().ForEach(m => IocManager.Register(m,DependencyLifeStyle.Multiple)); foreach (var dbContextType in dbContextTypes) { EntityFrameworkGenericRepositoryRegistrar.RegisterForDbContext(dbContextType, manager); } }
public static void Register(IIocManager iocManager) { var services = new ServiceCollection(); IdentityRegistrar.Register(services); services.AddEntityFrameworkInMemoryDatabase(); var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services); var builder = new DbContextOptionsBuilder <MySuperStatsDbContext>(); builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider); iocManager.IocContainer.Register( Component .For <DbContextOptions <MySuperStatsDbContext> >() .Instance(builder.Options) .LifestyleSingleton() ); }
public virtual void RegisterRepositories(IIocManager iocManager, AutoRepositoryTypesAttribute defaultRepositoryTypes) { AutoRepositoryTypesAttribute autoRepositoryAttr = _dbContextType.GetTypeInfo().GetSingleAttributeOrNull <AutoRepositoryTypesAttribute>() ?? defaultRepositoryTypes; foreach (EntityTypeInfo entityTypeInfo in _dbContextEntityFinder.GetEntityTypeInfos(_dbContextType)) { Type primaryKeyType = EntityHelper.GetPrimaryKeyType(entityTypeInfo.EntityType); if (primaryKeyType == typeof(int)) { Type genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityTypeInfo.EntityType); if (!iocManager.IsRegistered(genericRepositoryType)) { Type implType = autoRepositoryAttr.RepositoryImplementation.GetTypeInfo().GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.EntityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType); iocManager.Register( genericRepositoryType, implType, DependencyLifeStyle.Transient ); } } Type genericRepositoryTypeWithPrimaryKey = autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType); if (!iocManager.IsRegistered(genericRepositoryTypeWithPrimaryKey)) { Type implType = autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.GetTypeInfo().GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); iocManager.Register( genericRepositoryTypeWithPrimaryKey, implType, DependencyLifeStyle.Transient ); } } }
/// <summary> /// 配置微信小程序 /// </summary> public static void Config(ILogger logger, IIocManager iocManager, IConfigurationRoot config, ISettingManager settingManager) { //日志函数 void LogAction(string tag, string message) { if (tag.Equals("error", StringComparison.CurrentCultureIgnoreCase)) { logger.Error(message); } else { logger.Debug(message); } } var configInfo = new DefaultMiniProgramConfig { MiniProgramAppId = config["WeChat:MiniProgram:AppId"], MiniProgramAppSecret = config["WeChat:MiniProgram:AppSecret"] }; //从用户设置读取配置 if (Convert.ToBoolean(settingManager.GetSettingValue(AppSettings.WeChatMiniProgram.IsActive))) { configInfo.MiniProgramAppId = settingManager.GetSettingValue(AppSettings.WeChatMiniProgram.AppId); configInfo.MiniProgramAppSecret = settingManager.GetSettingValue(AppSettings.WeChatMiniProgram.AppSecret); } MiniProgramSDKBuilder.Create() //设置日志记录 .WithLoggerAction(LogAction).RegisterGetKeyFunc(() => { var key = iocManager.Resolve <IAbpSession>()?.TenantId; if (key == null) { return("0"); } return(key.ToString()); }).RegisterGetConfigByKeyFunc(key => configInfo).Build(); }
public void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { var autoRepositoryAttr = dbContextType.GetSingleAttributeOrNull <AutoRepositoryTypesAttribute>() ?? EfCoreAutoRepositoryTypes.Default; foreach (var entityTypeInfo in DbContextHelper.GetEntityTypeInfos(dbContextType)) { var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityTypeInfo.EntityType); if (primaryKeyType == typeof(int)) { var genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityTypeInfo.EntityType); if (!iocManager.IsRegistered(genericRepositoryType)) { var implType = autoRepositoryAttr.RepositoryImplementation.GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.EntityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType); iocManager.Register( genericRepositoryType, implType, DependencyLifeStyle.Transient ); } } var genericRepositoryTypeWithPrimaryKey = autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType); if (!iocManager.IsRegistered(genericRepositoryTypeWithPrimaryKey)) { var implType = autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); iocManager.Register( genericRepositoryTypeWithPrimaryKey, implType, DependencyLifeStyle.Transient ); } } }
private MSBootStrapper([NotNull] Type startupModule, [CanBeNull] Action <MSBootstrapperOptions> optionsAction = null) { var options = new MSBootstrapperOptions(); optionsAction?.Invoke(options); if (!typeof(MSModule).GetTypeInfo().IsAssignableFrom(startupModule)) { throw new ArgumentException($"{nameof(startupModule)} should be derived from {nameof(MSModule)}."); } StartupModule = startupModule; IocManager = options.IocManager; _logger = NullLogger.Instance; if (!options.DisableAllInterceptors) { AddInterceptorRegistrars(); } }
protected virtual void RegisterDependencies(XHConfig config) { var builder = new ContainerBuilder(); var container = builder.Build(); this._containerManager = new ContainerManager(container); //we create new instance of ContainerBuilder //because Build() or Update() method can only be called once on a ContainerBuilder. //dependencies var typeFinder = new WebAppTypeFinder(); builder = new ContainerBuilder(); builder.RegisterInstance(config).As <XHConfig>().SingleInstance(); builder.RegisterInstance(this).As <IEngine>().SingleInstance(); builder.RegisterInstance(typeFinder).As <ITypeFinder>().SingleInstance(); builder.Update(container); //register dependencies provided by other assemblies builder = new ContainerBuilder(); var drTypes = typeFinder.FindClassesOfType <IDependencyRegistrar>(); var drInstances = new List <IDependencyRegistrar>(); foreach (var drType in drTypes) { drInstances.Add((IDependencyRegistrar)Activator.CreateInstance(drType)); } //sort drInstances = drInstances.AsQueryable().OrderBy(t => t.Order).ToList(); foreach (var dependencyRegistrar in drInstances) { dependencyRegistrar.Register(builder, typeFinder, config); } builder.Update(container); //set dependency resolver DependencyResolver.SetResolver(new AutofacDependencyResolver(container)); }
public static void Register(IIocManager iocManager) { var services = new ServiceCollection(); WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services); var builder = new DbContextOptionsBuilder <TestDbContext>(); var inMemorySqlite = new SqliteConnection("Data Source=:memory:"); builder.UseSqlite(inMemorySqlite); iocManager.IocContainer.Register( Component .For <DbContextOptions <TestDbContext> >() .Instance(builder.Options) .LifestyleSingleton() ); inMemorySqlite.Open(); new TestDbContext(builder.Options).Database.EnsureCreated(); }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException); DevExpress.UserSkins.BonusSkins.Register(); DevExpress.Utils.AppearanceObject.DefaultFont = new Font("Segoe UI", 8); DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle("Office 2019 Colorful"); DevExpress.Skins.SkinManager.EnableMdiFormSkins(); //加载IOC容器 IIocManager iocManager = AbpApplicationBuilderExtensions.UseAbp <ZtgeoGISDesktopMoudle>(new SplashScreenFormManager(), optionAction => { optionAction.IocManager.IocContainer.AddFacility <LoggingFacility>( f => f.UseAbpLog4Net().WithConfig("log4net.config") ); }); //初始化界面 IMainForm mainForm = iocManager.Resolve <IMainForm>(); if (mainForm != null) { #region 全局异常处理 Application.ThreadException += (object sender, ThreadExceptionEventArgs e) => { EventBus.Default.Trigger <UIExceptionEventData>(new UIExceptionEventData { ThreadExceptionEventArgs = e }); }; AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler((object sender, UnhandledExceptionEventArgs e) => { EventBus.Default.Trigger <NonUIExceptionEventData>(new NonUIExceptionEventData { UnhandledExceptionEventArgs = e }); }); #endregion Application.Run((Form)mainForm); } }
private static void RegisterDbContextToSqliteInMemoryDb(IIocManager iocManager) { var builder = new DbContextOptionsBuilder <MyDbContext>(); builder.ReplaceService <IEntityMaterializerSource, AbpEntityMaterializerSource>(); var inMemorySqlite = new SqliteConnection("Data Source=:memory:"); builder.UseSqlite(inMemorySqlite); iocManager.IocContainer.Register( Component .For <DbContextOptions <MyDbContext> >() .Instance(builder.Options) .LifestyleSingleton() ); inMemorySqlite.Open(); var ctx = new MyDbContext(builder.Options); ctx.Database.EnsureCreated(); }
public static void Register(IIocManager iocManager) { var services = new ServiceCollection(); IdentityRegistrar.Register(services); services.AddEntityFrameworkInMemoryDatabase(); var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services); var builder = new DbContextOptionsBuilder <MindfightsDbContext>(); builder.UseInMemoryDatabase(Guid.NewGuid().ToString()).UseInternalServiceProvider(serviceProvider); iocManager.IocContainer.Register( Component .For <DbContextOptions <MindfightsDbContext> >() .Instance(builder.Options) .LifestyleSingleton() ); iocManager.Register(typeof(IPlayerService), typeof(Player), DependencyLifeStyle.Transient); iocManager.Register(typeof(ITeamService), typeof(Team), DependencyLifeStyle.Transient); iocManager.Register(typeof(IMindfightService), typeof(Mindfight), DependencyLifeStyle.Transient); iocManager.Register(typeof(IQuestionService), typeof(Question), DependencyLifeStyle.Transient); iocManager.Register(typeof(ITeamAnswerService), typeof(TeamAnswer), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRegistrationService), typeof(Registration), DependencyLifeStyle.Transient); iocManager.Register(typeof(IResultService), typeof(Result), DependencyLifeStyle.Transient); iocManager.Register(typeof(ITourService), typeof(Tour), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.City, long>), typeof(Models.City), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.Team, long>), typeof(Models.Team), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.Mindfight, long>), typeof(Models.Mindfight), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.Question, long>), typeof(Models.Question), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.TeamAnswer, long>), typeof(Models.TeamAnswer), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.Registration, long>), typeof(Models.Registration), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.MindfightResult, long>), typeof(Models.MindfightResult), DependencyLifeStyle.Transient); iocManager.Register(typeof(IRepository <Models.Tour, long>), typeof(Models.Tour), DependencyLifeStyle.Transient); }
public TestBaseWithLocalIocManager() { LocalIocManager = new IocManager(); /* * 需要注意注册的次序! * 先注册拦截器 */ //开启uow事务 UnitOfWorkRegistrar.Initialize(LocalIocManager); LocalIocManager.IocContainer.Register( Component.For(typeof(IDbContextProvider <>)).ImplementedBy(typeof(UnitOfWorkDbContextProvider <>)).LifestyleTransient(), Component.For <IUnitOfWorkDefaultOptions, UnitOfWorkDefaultOptions>().ImplementedBy <UnitOfWorkDefaultOptions>().LifestyleSingleton(), Component.For <IIocResolver, IocManager>().ImplementedBy <IocManager>().LifestyleSingleton(), Component.For <IUnitOfWorkManager>().ImplementedBy <UnitOfWorkManager>().LifestyleSingleton() ); LocalIocManager.Register(typeof(UnitOfWorkInterceptor), DependencyLifeStyle.Singleton); //IocManager.Register<HelpController>(DependencyLifeStyle.Transient); LocalIocManager.IocContainer.Install(new FinderInstaller()); LocalIocManager.AddConventionalRegistrar(new BasicConventionalRegistrar()); LocalIocManager.RegisterAssemblyByConvention(typeof(IRepository).Assembly); LocalIocManager.RegisterAssemblyByConvention(typeof(DomainServiceBase).Assembly); LocalIocManager.RegisterAssemblyByConvention(typeof(AppServiceBase).Assembly); //LocalIocManager.RegisterAssemblyByConvention(typeof(TestBaseWithLocalIocManager).Assembly); //LocalIocManager.RegisterAssemblyByConvention(Assembly.Load("DDD.Domain.Common")); LocalIocManager.RegisterAssemblyByConvention(Assembly.Load("DDD.Domain.Core")); LocalIocManager.RegisterAssemblyByConvention(Assembly.Load("DDD.Domain.Service")); //IocManager.Register<IBlogRepository>(); //IocManager.Register<IUserRepository>(); }
/// <summary> /// Creates a new <see cref="Bootstrapper"/> instance. /// </summary> /// <param name="startupModule">Startup module of the application which depends on other used modules. Should be derived from <see cref="AbpModule"/>.</param> /// <param name="optionsAction">An action to set options</param> private Bootstrapper(Type startupModule, Action <BootstrapperOptions> optionsAction = null) { var options = new BootstrapperOptions(); optionsAction?.Invoke(options); if (!typeof(BaseModule).GetTypeInfo().IsAssignableFrom(startupModule)) { throw new ArgumentException($"{nameof(startupModule)} should be derived from {nameof(BaseModule)}."); } StartupModule = startupModule; IocManager = options.IocManager; PlugInSources = options.PlugInSources; _logger = NullLogger.Instance; if (!options.DisableAllInterceptors) { AddInterceptorRegistrars(); } }
static TResult Forward <TResult>(ControllerContext controllerContext, IIocManager iIocManager, Func <IThemeAwareViewEngine, TResult> forwardAction, Func <TResult> defaultAction) { // var workContext = controllerContext.GetWorkContext(); // if (workContext != null) // { // var displayViewEngine = workContext.Resolve<IThemeAwareViewEngine>(); // if (displayViewEngine != null) // { // return forwardAction(displayViewEngine); // } // } if (iIocManager != null) { var displayViewEngine = iIocManager.Resolve <IThemeAwareViewEngine>(); if (displayViewEngine != null) { return(forwardAction(displayViewEngine)); } } return(defaultAction()); }
public void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { var RepositoryInterface = typeof(IExtendedRepository <>); var RepositoryImplementation = typeof(EfRepositoryBase <,>); foreach (EntityTypeInfo entityTypeInfo in ExtendedDbContextHelper.GetDbEntityTypeInfos(dbContextType)) { Type genericRepositoryType = RepositoryInterface.MakeGenericType(new Type[] { entityTypeInfo.EntityType }); if (!iocManager.IsRegistered(genericRepositoryType)) { Type implType = (RepositoryImplementation.GetGenericArguments().Length == 1) ? RepositoryImplementation.MakeGenericType(new Type[] { entityTypeInfo.EntityType }) : RepositoryImplementation.MakeGenericType(new Type[] { entityTypeInfo.DeclaringType, entityTypeInfo.EntityType }); iocManager.Register(genericRepositoryType, implType, DependencyLifeStyle.Transient); } } }
private void RegisterForDbContext( Type dbContextType, IIocManager iocManager, Type repositoryInterface, Type repositoryInterfaceWithPrimaryKey, Type repositoryImplementation, Type repositoryImplementationWithPrimaryKey) { foreach (var entityTypeInfo in _dbContextEntityFinder.GetEntityTypeInfos(dbContextType)) { var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityTypeInfo.EntityType); if (primaryKeyType == typeof(int)) { var genericRepositoryType = repositoryInterface.MakeGenericType(entityTypeInfo.EntityType); if (!iocManager.IsRegistered(genericRepositoryType)) { var implType = repositoryImplementation.GetGenericArguments().Length == 1 ? repositoryImplementation.MakeGenericType(entityTypeInfo.EntityType) : repositoryImplementation.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType); iocManager.IocContainer.Register(genericRepositoryType, implType, Reuse.Transient); } } var genericRepositoryTypeWithPrimaryKey = repositoryInterfaceWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType); if (!iocManager.IsRegistered(genericRepositoryTypeWithPrimaryKey)) { var implType = repositoryImplementationWithPrimaryKey.GetGenericArguments().Length == 2 ? repositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType) : repositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); iocManager.IocContainer.Register(genericRepositoryTypeWithPrimaryKey, implType, Reuse.Transient); } } }
/// <summary> /// Creates a new <see cref="AbpBootstrapper"/> instance. /// </summary> /// <param name="startupModule">Startup module of the application which depends on other used modules. Should be derived from <see cref="AbpModule"/>.</param> /// <param name="optionsAction">An action to set options</param> private AbpBootstrapper( [NotNull] Type startupModule, [CanBeNull] Action <AbpBootstrapperOptions> optionsAction = null) { Check.NotNull(startupModule, nameof(startupModule)); var options = new AbpBootstrapperOptions(); optionsAction?.Invoke(options); if (!typeof(AbpModule).GetTypeInfo().IsAssignableFrom(startupModule)) { throw new ArgumentException($"{nameof(startupModule)} should be derived from {nameof(AbpModule)}."); } StartupModule = startupModule; IocManager = options.IocManager; PlugInSources = options.PlugInSources; _logger = NullLogger.Instance; AddInterceptorRegistrars(options.InterceptorOptions); }
public OracleTestBaseWithLocalIocManager() { LocalIocManager = new IocManager(); /* * 需要注意注册的次序! * 先注册拦截器 */ //开启uow事务 UnitOfWorkRegistrar.Initialize(LocalIocManager); LocalIocManager.IocContainer.Register( Component.For(typeof(IDbContextProvider <>)).ImplementedBy(typeof(UnitOfWorkDbContextProvider <>)).LifestyleTransient(), Component.For <IUnitOfWorkDefaultOptions, UnitOfWorkDefaultOptions>().ImplementedBy <UnitOfWorkDefaultOptions>().LifestyleSingleton(), Component.For <IIocResolver, IocManager>().ImplementedBy <IocManager>().LifestyleSingleton(), Component.For <IUnitOfWorkManager>().ImplementedBy <UnitOfWorkManager>().LifestyleSingleton() //Component.For<IAutoMapperInitializer, AutoMapperInitializer>().ImplementedBy<AutoMapperInitializer>().LifestyleSingleton() ); LocalIocManager.Register(typeof(UnitOfWorkInterceptor), DependencyLifeStyle.Singleton); //IocManager.Register<HelpController>(DependencyLifeStyle.Transient); LocalIocManager.IocContainer.Install(new FinderInstaller()); LocalIocManager.AddConventionalRegistrar(new BasicConventionalRegistrar()); LocalIocManager.RegisterAssemblyByConvention(typeof(IAutoMapperModule).Assembly); LocalIocManager.RegisterAssemblyByConvention(typeof(IInfrastructureDomainModule).Assembly); LocalIocManager.RegisterAssemblyByConvention(typeof(IDomainCoreModule).Assembly); LocalIocManager.RegisterAssemblyByConvention(typeof(IDomainServiceModule).Assembly); LocalIocManager.RegisterAssemblyByConvention(typeof(IAppServiceModule).Assembly); }
public void Register(IIocManager iocManager) { var services = new ServiceCollection(); IdentityRegistrar.Register(services); services.AddEntityFrameworkSqlite(); var serviceProvider = WindsorRegistrationHelper.CreateServiceProvider(iocManager.IocContainer, services); // In-memory database only exists while the connection is open _connection = new SqliteConnection("DataSource=:memory:"); _connection.Open(); var builder = new DbContextOptionsBuilder <AcmStatisticsBackendDbContext>(); builder.UseSqlite(_connection).UseInternalServiceProvider(serviceProvider); iocManager.IocContainer.Register( Component .For <DbContextOptions <AcmStatisticsBackendDbContext> >() .Instance(builder.Options) .LifestyleSingleton()); }
private WindBootstrapper(Type startupModule, IIocManager iocManager) { if (startupModule == null) { throw new ArgumentNullException("startupModule"); } if (iocManager == null) { throw new ArgumentNullException("iocManager"); } if (!typeof(WindModule).IsAssignableFrom(startupModule)) { throw new ArgumentException(startupModule + " should be derived from WindModule."); } StartupModule = startupModule; IocManager = iocManager; PlugInSources = new PlugInSourceList(); _logger = NullLogger.Instance; AddInterceptorRegistrars(); }
/// <summary> /// Constructor. /// </summary> public SettingDefinitionManager(IIocManager iocManager, ISettingsConfiguration settingsConfiguration) { this.iocManager = iocManager; this.settingsConfiguration = settingsConfiguration; settings = new Dictionary <string, SettingDefinition>(); }
/// <summary> /// 创建系统启动器 /// </summary> /// <typeparam name="TStartupModule">模块</typeparam> /// <param name="iocManager">容器管理器</param> public static DcpBootstrapper Create <TStartupModule>(IIocManager iocManager) where TStartupModule : DcpModule => new DcpBootstrapper(typeof(TStartupModule), iocManager);
/// <summary> /// 创建启动器 /// </summary> /// <param name="startupModule"></param> /// <param name="iocManager"></param> public static DcpBootstrapper Create(Type startupModule, IIocManager iocManager) => new DcpBootstrapper(startupModule, iocManager);
public CncCoreWorker(IIocManager _iocManager) { iocManager = _iocManager; }
public NavigationTestCase(IIocManager iocManager) { _iocManager = iocManager; Initialize(); }
/// <summary> /// Constructor. /// </summary> public AbpMemoryCacheManager(IIocManager iocManager, ICachingConfiguration configuration) : base(iocManager, configuration) { IocManager.RegisterIfNot <AbpMemoryCache>(DependencyLifeStyle.Transient); }
public ExternalLoginInfoManagerFactory(IIocManager iocManager) { _iocManager = iocManager; }
public static void RegisterAssembly(IIocManager iocManager) { iocManager.RegisterAssemblyByConvention(typeof(QksPluginDbContext).GetAssembly()); }
/// <summary> /// Initializes a new instance of the <see cref="MultiTenantLocalizationDictionaryProvider"/> class. /// </summary> public MultiTenantLocalizationDictionaryProvider(ILocalizationDictionaryProvider internalProvider, IIocManager iocManager) { _internalProvider = internalProvider; _iocManager = iocManager; _dictionaries = new ConcurrentDictionary <string, ILocalizationDictionary>(); }
public static void Initialize(IIocManager iocManager) { iocManager.IocContainer.Kernel.ComponentRegistered += Kernel_ComponentRegistered; }