public void RegisterForDbContext( Type dbContextType, IIocManager iocManager, AutoRepositoryTypesAttribute defaultAutoRepositoryTypesAttribute) { var autoRepositoryAttr = dbContextType.GetTypeInfo().GetSingleAttributeOrNull <AutoRepositoryTypesAttribute>() ?? defaultAutoRepositoryTypesAttribute; RegisterForDbContext( dbContextType, iocManager, autoRepositoryAttr.RepositoryInterface, autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey, autoRepositoryAttr.RepositoryImplementation, autoRepositoryAttr.RepositoryImplementationWithPrimaryKey ); if (autoRepositoryAttr.WithDefaultRepositoryInterfaces) { RegisterForDbContext( dbContextType, iocManager, defaultAutoRepositoryTypesAttribute.RepositoryInterface, defaultAutoRepositoryTypesAttribute.RepositoryInterfaceWithPrimaryKey, autoRepositoryAttr.RepositoryImplementation, autoRepositoryAttr.RepositoryImplementationWithPrimaryKey ); } }
public static void RegisterRepositories(Type dbContextType, IIocBuilder builder) { AutoRepositoryTypesAttribute autoRepositoryAttr = dbContextType.GetSingleAttributeOrNull <DapperAutoRepositoryTypeAttribute>() ?? DapperAutoRepositoryTypes.Default; foreach (EntityTypeInfo entityTypeInfo in DbContextHelper.GetEntityTypeInfos(dbContextType)) { Type implType; Type primaryKeyType = EntityHelper.GetPrimaryKeyType(entityTypeInfo.EntityType); if (primaryKeyType == typeof(int)) { Type genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityTypeInfo.EntityType); implType = autoRepositoryAttr.RepositoryImplementation.GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.EntityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType); builder.RegisterServices(r => r.UseBuilder(cb => cb.RegisterType(implType).As(genericRepositoryType).AsImplementedInterfaces().InjectPropertiesAsAutowired())); } else { Type genericRepositoryTypeWithPrimaryKey = autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType); implType = autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); builder.RegisterServices(r => r.UseBuilder(cb => cb.RegisterType(implType).As(genericRepositoryTypeWithPrimaryKey).AsImplementedInterfaces().InjectPropertiesAsAutowired())); } } }
public void RegisterRepositories(AutoRepositoryTypesAttribute defaultRepositoryTypes) { AutoRepositoryTypesAttribute autoRepositoryAttr = defaultRepositoryTypes; foreach (EntityTypeInfo entityTypeInfo in _entityTypeInfoFinder(_dbContextType)) { Type implType; Type primaryKeyType = _primaryKeyTypeFinder(entityTypeInfo.EntityType); if (primaryKeyType == typeof(int)) { Type genericRepositoryType = autoRepositoryAttr.RepositoryInterface.MakeGenericType(entityTypeInfo.EntityType); implType = autoRepositoryAttr.RepositoryImplementation.GetGenericArguments().Length == 1 ? autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.EntityType) : autoRepositoryAttr.RepositoryImplementation.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType); _iocBuilder.RegisterServices(r => r.UseBuilder(cb => cb.RegisterType(implType).As(genericRepositoryType).AsSelf().AsImplementedInterfaces().WithPropertyInjection())); } else { Type genericRepositoryTypeWithPrimaryKey = autoRepositoryAttr.RepositoryInterfaceWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType); implType = autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); _iocBuilder.RegisterServices(r => r.UseBuilder(cb => cb.RegisterType(implType).As(genericRepositoryTypeWithPrimaryKey).AsSelf().AsImplementedInterfaces().WithPropertyInjection())); } } }
public void RegisterRepositories(AutoRepositoryTypesAttribute defaultRepositoryTypes) { _iocBuilder.RegisterServices(r => { r.RegisterGeneric(defaultRepositoryTypes.RepositoryInterface, defaultRepositoryTypes.RepositoryImplementation); r.RegisterGeneric(defaultRepositoryTypes.RepositoryInterfaceWithPrimaryKey, defaultRepositoryTypes.RepositoryImplementationWithPrimaryKey); }); }
static EfAutoRepositoryTypes() { Default = new AutoRepositoryTypesAttribute( typeof(IRepository <>), typeof(IRepository <,>), typeof(EfRepositoryBase <,>), typeof(EfRepositoryBase <, ,>) ); }
static EfAutoRepositoryTypes() { Default = new AutoRepositoryTypesAttribute( typeof(IRepositoryWithEntity <>), typeof(IRepositoryWithTEntityAndTPrimaryKey <,>), typeof(EfRepositoryBase <,>), typeof(EfRepositoryBase <, ,>) ); }
static DapperAutoRepositoryTypes() { Default = new AutoRepositoryTypesAttribute( typeof(IDapperRepository <>), typeof(IDapperRepository <,>), typeof(DapperRepositoryBase <,>), typeof(DapperRepositoryBase <, ,>) ); }
static EfAutoRepositoryTypes() { Default = new AutoRepositoryTypesAttribute( typeof(Blocks.Framework.Data.IRepository<>), typeof(IRepository<,>), typeof(DBSqlRepositoryBase<>), typeof(DBSqlRepositoryBase<,,>) ); }
public virtual void RegisterRepositories(IIocManager iocManager, AutoRepositoryTypesAttribute defaultRepositoryTypes) { var autoRepositoryAttr = dbContextType.GetTypeInfo() .GetSingleAttributeOrNull <AutoRepositoryTypesAttribute>() ?? defaultRepositoryTypes; foreach (var entityTypeInfo in dbContextEntityFinder.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.GetTypeInfo().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.GetTypeInfo() .GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType( entityTypeInfo.EntityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType( entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); iocManager.Register( genericRepositoryTypeWithPrimaryKey, implType, DependencyLifeStyle.Transient ); } } }
public void RegisterRepositories(IIocManager iocManager, AutoRepositoryTypesAttribute defaultRepositoryTypes) { if (defaultRepositoryTypes.WithDefaultRepositoryInterfaces) { iocManager.IocContainer.Register( Component.For(typeof(IRepository <>), defaultRepositoryTypes.RepositoryInterface).ImplementedBy(defaultRepositoryTypes.RepositoryImplementation).LifestyleTransient(), Component.For(typeof(IRepository <,>), defaultRepositoryTypes.RepositoryInterfaceWithPrimaryKey).ImplementedBy(defaultRepositoryTypes.RepositoryImplementationWithPrimaryKey).LifestyleTransient() ); } else { iocManager.Register(defaultRepositoryTypes.RepositoryInterface, defaultRepositoryTypes.RepositoryImplementation, DependencyLifeStyle.Transient); iocManager.Register(defaultRepositoryTypes.RepositoryInterfaceWithPrimaryKey, defaultRepositoryTypes.RepositoryImplementationWithPrimaryKey, DependencyLifeStyle.Transient); } }
public void RegisterForDbContext(Type dbContextType, IIocManager iocManager) { AutoRepositoryTypesAttribute autoRepositoryAttr = dbContextType.GetSingleAttributeOrNull <DapperAutoRepositoryTypeAttribute>() ?? DapperAutoRepositoryTypes.Default; foreach (EntityTypeInfo entityTypeInfo in DbContextHelper.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.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.GetGenericArguments().Length == 2 ? autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.EntityType, primaryKeyType) : autoRepositoryAttr.RepositoryImplementationWithPrimaryKey.MakeGenericType(entityTypeInfo.DeclaringType, entityTypeInfo.EntityType, primaryKeyType); iocManager.Register( genericRepositoryTypeWithPrimaryKey, implType, DependencyLifeStyle.Transient ); } } }