/// <summary> /// RegisterMatchDbContexts /// </summary> private void RegisterMatchDbContexts() { if (IocManager == null) { return; } var types = _loadType.GetAll(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(WorkDataBaseDbContext).IsAssignableFrom(x)); var builder = new ContainerBuilder(); foreach (var type in types) { var entityTypeInfos = DbContextHelper.GetEntityTypeInfos(type); foreach (var entityTypeInfo in entityTypeInfos) { var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityTypeInfo.EntityType); var genericRepositoryType = typeof(IBaseRepository <,>).MakeGenericType(entityTypeInfo.EntityType, primaryKeyType); var baseImplType = typeof(EfBaseRepository <, ,>); var implType = baseImplType.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); builder.RegisterType(implType).As(genericRepositoryType); } } IocManager.UpdateContainer(builder); }
protected override void Load(ContainerBuilder builder) { builder.RegisterType <AuditableConfigs>() .SingleInstance(); builder.RegisterType <EfContextFactory>() .As <IEfContextFactory>(); builder.RegisterGeneric(typeof(DbContentProvider <>)) .As(typeof(IDbContextProvider <>)); builder.RegisterType <EfUnitOfWork>() .As <IUnitOfWork, IActiveUnitOfWork, IUnitOfWorkCompleteHandle>(); var auditTypes = _loadType.GetAll(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(IAuditable).IsAssignableFrom(x)); foreach (var auditType in auditTypes) { builder.RegisterType(auditType).Named <IAuditable>(auditType.FullName); } #region Repository注入 var types = _loadType.GetAll(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(WorkDataBaseDbContext).IsAssignableFrom(x)); foreach (var type in types) { var entityTypeInfos = DbContextHelper.GetEntityTypeInfos(type); foreach (var entityTypeInfo in entityTypeInfos) { var primaryKeyType = EntityHelper.GetPrimaryKeyType(entityTypeInfo.EntityType); var genericRepositoryType = typeof(IBaseRepository <,>).MakeGenericType(entityTypeInfo.EntityType, primaryKeyType); var baseImplType = typeof(EfBaseRepository <, ,>); var implType = baseImplType.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); builder.RegisterType(implType).As(genericRepositoryType); } } #endregion }
/// <summary> /// InitializedAuditables /// </summary> /// <param name="isReload"></param> public virtual void InitializedAuditables(bool isReload = false) { if (AuditableDictionary != null && AuditableDictionary.Any()) { return; } if (Auditables == null || isReload) { Auditables = new List <Auditable>(); } var types = _loadType.GetAll(x => x.IsPublic && x.IsClass && typeof(IAuditable).IsAssignableFrom(x)); foreach (var type in types) { var item = (AuditAttribute)type.GetCustomAttributes(typeof(AuditAttribute), true).FirstOrDefault(); if (item == null) { continue; } var auditable = new Auditable { EntityState = item.EntityState, AuditableImpl = IocManager.Instance.ResolveName <IAuditable>(type.FullName) }; Auditables.Add(auditable); } var addAuditables = Auditables.Where(x => x.EntityState == EntityState.Added). Select(x => x.AuditableImpl).ToList(); if (addAuditables.Any()) { AuditableDictionary?.Add(EntityState.Added, addAuditables); } var updateAuditables = Auditables.Where(x => x.EntityState == EntityState.Modified). Select(x => x.AuditableImpl).ToList(); if (updateAuditables.Any()) { AuditableDictionary?.Add(EntityState.Modified, updateAuditables); } var deleteAuditables = Auditables.Where(x => x.EntityState == EntityState.Deleted). Select(x => x.AuditableImpl).ToList(); if (deleteAuditables.Any()) { AuditableDictionary?.Add(EntityState.Deleted, deleteAuditables); } }
/// <summary> /// RegisterMatchDbContexts /// </summary> private void RegisterMatchDomainService() { if (IocManager == null) { return; } var types = _loadType.GetAll(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(IDomainService).IsAssignableFrom(x)); var builder = new ContainerBuilder(); foreach (var type in types) { builder.RegisterType(type).Named <IDomainService>(type.FullName); } IocManager.UpdateContainer(builder); }
/// <summary> /// RegisterMatchDbContexts /// </summary> private void RegisterMatchDbContexts() { if (IocManager == null) { return; } var types = _loadType.GetAll(x => x.IsPublic && x.IsClass && !x.IsAbstract && typeof(ICallBack).IsAssignableFrom(x)); var builder = new ContainerBuilder(); foreach (var type in types) { var baseImplType = typeof(DomainServiceProxy <>); var implType = baseImplType.MakeGenericType(type); builder.RegisterType(implType); } IocManager.UpdateContainer(builder); }