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 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 ); }
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 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 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 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 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 AbpNHibernateInterceptor(IIocManager iocManager) { _iocManager = iocManager; _abpSession = new Lazy<IAbpSession>( () => _iocManager.IsRegistered(typeof(IAbpSession)) ? _iocManager.Resolve<IAbpSession>() : NullAbpSession.Instance ); }
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 ); } } }
/// <summary> /// 支付宝支付配置 /// </summary> /// <param name="logAction"></param> /// <param name="iocManager"></param> /// <param name="config"></param> /// <param name="settingManager"></param> /// <returns></returns> private static async Task <AlipaySettings> AlipayConfig(Action <string, string> logAction, IIocManager iocManager, IConfigurationRoot config, ISettingManager settingManager) { #region 支付宝支付 AlipaySettings alipaySettings = null; if (Convert.ToBoolean(await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.IsActive))) { alipaySettings = new AlipaySettings { AlipayPublicKey = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.AlipayPublicKey), AppId = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.AppId), Uid = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.Uid), PrivateKey = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.PrivateKey), }; var charSet = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.CharSet); if (!charSet.IsNullOrWhiteSpace()) { alipaySettings.CharSet = charSet; } var gatewayurl = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.Gatewayurl); if (!gatewayurl.IsNullOrWhiteSpace()) { alipaySettings.Gatewayurl = gatewayurl; } var notify = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.Notify); if (!notify.IsNullOrWhiteSpace()) { alipaySettings.Notify = notify; } var signType = await settingManager.GetSettingValueAsync(AppSettings.AliPayManagement.SignType); if (!signType.IsNullOrWhiteSpace()) { alipaySettings.SignType = signType; } } else if (!config["Alipay:IsEnabled"].IsNullOrWhiteSpace() && Convert.ToBoolean(config["Alipay:IsEnabled"])) { alipaySettings = new AlipaySettings { AlipayPublicKey = config["Alipay:PublicKey"], AppId = config["Alipay:AppId"], Uid = config["Alipay:Uid"], PrivateKey = config["Alipay:PrivateKey"] }; if (!config["Alipay:CharSet"].IsNullOrWhiteSpace()) { alipaySettings.CharSet = config["Alipay:CharSet"]; } if (!config["Alipay:Gatewayurl"].IsNullOrWhiteSpace()) { alipaySettings.Gatewayurl = config["Alipay:Gatewayurl"]; } if (!config["Alipay:Notify"].IsNullOrWhiteSpace()) { alipaySettings.Notify = config["Alipay:Notify"]; } if (!config["Alipay:SignType"].IsNullOrWhiteSpace()) { alipaySettings.SignType = config["Alipay:SignType"]; } } if (alipaySettings != null) { AlipayBuilder.Create() .WithLoggerAction(logAction) .RegisterGetPayConfigFunc(() => alipaySettings).Build(); //注册支付宝支付API if (!iocManager.IsRegistered <IAlipayAppService>()) { iocManager.Register <IAlipayAppService, AlipayAppService>(DependencyLifeStyle.Transient); } } #endregion return(alipaySettings); }
/// <summary> /// Refresh configuration store instance using provided <paramref name="iocManager"/>. Note: for internal usage and unit-tests only /// </summary> /// <param name="iocManager"></param> public static void RefreshStore(IIocManager iocManager) { _configurationStore = iocManager.IsRegistered <IEntityConfigurationStore>() ? iocManager.Resolve <IEntityConfigurationStore>() : null; }