/// <summary> /// /// </summary> public static IOcelotBuilder UseSqlServer(this IOcelotBuilder builder) { builder.Services.AddSingleton <IFileConfigurationRepository, FileConfigurationRepository>(); builder.Services.AddSingleton <IClientAuthenticationRepository, ClientAuthenticationRepository>(); builder.Services.AddSingleton <IClientRateLimitRepository, ClientRateLimitRepository>(); return(builder); }
public static IOcelotBuilder AddConfigStoredInConsul(this IOcelotBuilder builder) { builder.Services.AddSingleton <OcelotMiddlewareConfigurationDelegate>(ConsulMiddlewareConfigurationProvider.Get); builder.Services.AddHostedService <FileConfigurationPoller>(); builder.Services.AddSingleton <IFileConfigurationRepository, ConsulFileConfigurationRepository>(); return(builder); }
public static IOcelotBuilder AddCacheManager(this IOcelotBuilder builder, Action <ConfigurationBuilderCachePart> settings) { var cacheManagerOutputCache = CacheFactory.Build <CachedResponse>("OcelotOutputCache", settings); var ocelotOutputCacheManager = new OcelotCacheManagerCache <CachedResponse>(cacheManagerOutputCache); builder.Services.RemoveAll(typeof(ICacheManager <CachedResponse>)); builder.Services.RemoveAll(typeof(IOcelotCache <CachedResponse>)); builder.Services.AddSingleton <ICacheManager <CachedResponse> >(cacheManagerOutputCache); builder.Services.AddSingleton <IOcelotCache <CachedResponse> >(ocelotOutputCacheManager); var ocelotConfigCacheManagerOutputCache = CacheFactory.Build <IInternalConfiguration>("OcelotConfigurationCache", settings); var ocelotConfigCacheManager = new OcelotCacheManagerCache <IInternalConfiguration>(ocelotConfigCacheManagerOutputCache); builder.Services.RemoveAll(typeof(ICacheManager <IInternalConfiguration>)); builder.Services.RemoveAll(typeof(IOcelotCache <IInternalConfiguration>)); builder.Services.AddSingleton <ICacheManager <IInternalConfiguration> >(ocelotConfigCacheManagerOutputCache); builder.Services.AddSingleton <IOcelotCache <IInternalConfiguration> >(ocelotConfigCacheManager); var fileConfigCacheManagerOutputCache = CacheFactory.Build <FileConfiguration>("FileConfigurationCache", settings); var fileConfigCacheManager = new OcelotCacheManagerCache <FileConfiguration>(fileConfigCacheManagerOutputCache); builder.Services.RemoveAll(typeof(ICacheManager <FileConfiguration>)); builder.Services.RemoveAll(typeof(IOcelotCache <FileConfiguration>)); builder.Services.AddSingleton <ICacheManager <FileConfiguration> >(fileConfigCacheManagerOutputCache); builder.Services.AddSingleton <IOcelotCache <FileConfiguration> >(fileConfigCacheManager); builder.Services.RemoveAll(typeof(ICacheKeyGenerator)); builder.Services.AddSingleton <ICacheKeyGenerator, CacheKeyGenerator>(); return(builder); }
public static IOcelotBuilder AddEureka(this IOcelotBuilder builder) { builder.Services.AddDiscoveryClient(builder.Configuration); builder.Services.AddSingleton <ServiceDiscoveryFinderDelegate>(EurekaProviderFactory.Get); builder.Services.AddSingleton <OcelotMiddlewareConfigurationDelegate>(EurekaMiddlewareConfigurationProvider.Get); return(builder); }
/// <summary> /// 实用redis存储替换IInternalConfigurationRepository的服务 /// </summary> /// <param name="ocelotBuilder"></param> /// <returns></returns> public static IOcelotBuilder AddRedisProvider(this IOcelotBuilder ocelotBuilder, Action <CacheOptions> options) { //获取数据 CacheOptions cacheOptions = new CacheOptions(); options?.Invoke(cacheOptions); //检验是否注入redis仓储 if (ocelotBuilder.Services.BuildServiceProvider().GetService <IRedisOperationHelp>() == null) { if (cacheOptions.RedisOptions == null) { throw new ArgumentNullException(nameof(cacheOptions.RedisOptions)); } //注入redis仓储 ocelotBuilder.Services.AddRedisRepository(cacheOptions.RedisOptions); } //更改扩展方式 ocelotBuilder.Services.RemoveAll(typeof(IInternalConfigurationRepository)); //重写ocelot每次请求获取配置的服务 ocelotBuilder.Services.AddSingleton <IInternalConfigurationRepository, RedisInternalConfigurationRepository>(); return(ocelotBuilder); }
public static IOcelotBuilder AddOrleansHttpGateway(this IOcelotBuilder builder, Action <OrleansRequesterConfiguration> OrleansRequesterConfiguration = null) { builder.Services.AddOrleansHttpGateway(OrleansRequesterConfiguration); builder.Services.Configure <OrleansHttpGatewayOptions>(builder.Configuration.GetSection("Orleans")); return(builder); }
public static IOcelotBuilder AddSecurityAuthorizationToken(this IOcelotBuilder builder, Action <DbContextOptionsBuilder> optionsAction) { builder.Services.AddSingleton <IAuthorizationTokenStorage, AuthorizationTokenStorage>(); builder.Services.AddSingleton <ISecurityPolicy, AuthorizationTokenSecurityPolicy>(); builder.Services.AddDbContext <OcelotSecurityStorageDbContent>(optionsAction); return(builder); }
public static IOcelotBuilder AddNacosDiscovery(this IOcelotBuilder builder) { builder.Services.AddNacosAspNet(builder.Configuration); builder.Services.AddSingleton <ServiceDiscoveryFinderDelegate>(NacosProviderFactory.Get); builder.Services.AddSingleton <OcelotMiddlewareConfigurationDelegate>(NacosMiddlewareConfigurationProvider.Get); return(builder); }
/// <summary> /// 愉快的使用ocelot了 /// </summary> /// <param name="builder"></param> /// <param name="usePodServiceAccount"></param> /// <returns></returns> public static IOcelotBuilder AddKubernetesFixed(this IOcelotBuilder builder, bool usePodServiceAccount = true) { builder.Services.AddSingleton(FixedKubernetesProviderFactoryGet); builder.Services.AddKubeClient(usePodServiceAccount); return(builder); }
/// <summary> /// 更改ocelot的存储方式为使用redis /// </summary> /// <param name="ocelotBuilder"></param> /// <returns></returns> public static IOcelotBuilder AddRedisCache(this IOcelotBuilder ocelotBuilder, Action <CacheOptions> options) { //获取数据 CacheOptions cacheOptions = new CacheOptions(); options?.Invoke(cacheOptions); //验证仓储服务是否注册 if (ocelotBuilder.Services.BuildServiceProvider().GetService <IRedisOperationHelp>() == null) { if (cacheOptions != null && cacheOptions.RedisOptions != null) { ocelotBuilder.Services.AddRedisRepository(cacheOptions.RedisOptions); } else { throw new ApplicationException("当前检查没有配置Redis仓储服务"); } } //更改扩展方式 ocelotBuilder.Services.RemoveAll(typeof(IOcelotCache <FileConfiguration>)); ocelotBuilder.Services.RemoveAll(typeof(IOcelotCache <CachedResponse>)); ocelotBuilder.Services.TryAddSingleton <IOcelotCache <FileConfiguration>, OcelotRedisManagerCache <FileConfiguration> >(); ocelotBuilder.Services.TryAddSingleton <IOcelotCache <CachedResponse>, OcelotRedisManagerCache <CachedResponse> >(); ocelotBuilder.Services.RemoveAll(typeof(IFileConfigurationRepository)); //重写提取Ocelot配置信息 ocelotBuilder.Services.AddSingleton(RedisConfigurationProvider.Get); ocelotBuilder.Services.AddSingleton <IFileConfigurationRepository, RedisConfigurationRepository>(); return(ocelotBuilder); }
public static IOcelotBuilder AddNacos(this IOcelotBuilder builder) { builder.Services.AddNacosAspNet(builder.Configuration); builder.Services.AddSingleton(NacosProviderFactory.Get); builder.Services.AddSingleton(NacosMiddlewareConfigurationProvider.Get); return(builder); }
public static IOcelotBuilder AddAhphOcelot(this IOcelotBuilder builder, Action <AhphOcelotConfiguration> action) { builder.Services.Configure(action); //配置信息 builder.Services.AddSingleton( resolver => resolver.GetRequiredService <IOptions <AhphOcelotConfiguration> >().Value); //文件仓储注入 builder.Services.AddSingleton <IFileConfigurationRepository, SqlServerFileConfigurationRepository>(); builder.Services.AddSingleton <IClientAuthenticationRepository, SqlServerClientAuthenticationRepository>(); //注册后端服务 builder.Services.AddHostedService <DbConfigurationPoller>(); //使用Redis重写缓存 //builder.Services.AddSingleton(typeof(IOcelotCache<>), typeof(InRedisCache<>)); builder.Services.AddSingleton <IOcelotCache <FileConfiguration>, InRedisCache <FileConfiguration> >(); builder.Services.AddSingleton <IOcelotCache <CachedResponse>, InRedisCache <CachedResponse> >(); builder.Services.AddSingleton <IInternalConfigurationRepository, RedisInternalConfigurationRepository>(); builder.Services.AddSingleton <IOcelotCache <ClientRoleModel>, InRedisCache <ClientRoleModel> >(); builder.Services.AddSingleton <IOcelotCache <RateLimitRuleModel>, InRedisCache <RateLimitRuleModel> >(); builder.Services.AddSingleton <IOcelotCache <AhphClientRateLimitCounter?>, InRedisCache <AhphClientRateLimitCounter?> >(); //注入授权 builder.Services.AddSingleton <IAhphAuthenticationProcessor, AhphAuthenticationProcessor>(); // 注入限流 builder.Services.AddSingleton <IClientRateLimitProcessor, AhphClientRateLimitProcessor>(); builder.Services.AddSingleton <IClientRateLimitRepository, SqlServerClientRateLimitRepository>(); //重写错误状态码 builder.Services.AddSingleton <IErrorsToHttpStatusCodeMapper, AhphErrorsToHttpStatusCodeMapper>(); return(builder); }
/// <summary> /// 更改ocelot的存储方式为使用EF /// </summary> /// <param name="ocelotBuilder"></param> /// <returns></returns> public static IOcelotBuilder AddOcelotEFCache(this IOcelotBuilder ocelotBuilder, Action <CacheOptions> options) { //获取数据 CacheOptions cacheOptions = new CacheOptions(); options?.Invoke(cacheOptions); OcelotEFOption eFOptions = new OcelotEFOption(); cacheOptions?.EFOptions.Invoke(eFOptions); #region 注入仓储 ocelotBuilder.Services.AddRepository(); ocelotBuilder.Services.AddEFOption(ocelot => { ocelot.ConfigureDbContext = eFOptions.ConfigureDbContext; ocelot.ReadOnlyConnectionString = eFOptions.ReadOnlyConnectionString; // ocelot.UseEntityFramework <OcelotDbContent, SlaveOcelotDbContent>(); ocelot.IsOpenMasterSlave = eFOptions.IsOpenMasterSlave; }); #endregion //更改扩展方式 ocelotBuilder.Services.RemoveAll(typeof(IFileConfigurationRepository)); //重写提取Ocelot配置信息 ocelotBuilder.Services.AddSingleton(EFConfigurationProvider.Get); ocelotBuilder.Services.AddSingleton <IFileConfigurationRepository, EFConfigurationRepository>(); return(ocelotBuilder); }
public static IOcelotBuilder AddConsul(this IOcelotBuilder builder) { builder.Services.AddSingleton <ServiceDiscoveryFinderDelegate>(ConsulProviderFactory.Get); builder.Services.AddSingleton <IConsulClientFactory, ConsulClientFactory>(); builder.Services.RemoveAll(typeof(IFileConfigurationPollerOptions)); builder.Services.AddSingleton <IFileConfigurationPollerOptions, ConsulFileConfigurationPollerOption>(); return(builder); }
/// <summary> /// Store OcelotConfiguration in EntityFramework /// </summary> /// <param name="builder">the OcelotBuilder</param> /// <param name="optionsAction">Ocelot DbContext optionsAction</param> /// <returns>the OcelotBuilder</returns> public static IOcelotBuilder StoreConfigurationInEntityFramework(this IOcelotBuilder builder, Action <DbContextOptionsBuilder> optionsAction) { builder.Services.AddDbContextPool <OcelotDbContext>(optionsAction, poolSize: 100); // dbContextPool size tip https://www.cnblogs.com/dudu/p/10398225.html builder.Services.AddSingleton <IFileConfigurationRepository, EntityFrameworkConfigurationRepository>(); return(builder); }
public static IOcelotBuilder AddConfigurationRepository(this IOcelotBuilder builder, Action <GatewayConfiguration> options) { builder.Services.Configure(options); builder.Services.AddSingleton(option => option.GetRequiredService <IOptions <GatewayConfiguration> >().Value); builder.Services.AddHostedService <DBConfigurationPoller>(); builder.Services.AddSingleton <IFileConfigurationRepository, MySqlFileConfigurationRepository>(); return(builder); }
/// <summary> /// StoreConfigurationInEntityFramework /// </summary> /// <param name="builder">the OcelotBuilder</param> /// <param name="optionsAction">Ocelot DbContext optionsAction</param> /// <returns>the OcelotBuilder</returns> public static IOcelotBuilder StoreConfigurationInRedis(this IOcelotBuilder builder, Action <RedisFileConfigurationOptions> optionsAction) { if (optionsAction != null) { builder.Services.Configure(optionsAction); } builder.Services.AddSingleton <IFileConfigurationRepository, RedisFileConfigurationRepository>(); return(builder); }
/// <summary> /// 添加ASF /// </summary> /// <param name="builder"></param> /// <param name="startupAction">配置ASF函数</param> /// <returns></returns> public static IOcelotBuilder AddASF(this IOcelotBuilder builder, Action <ASFBuilder> startupAction) { builder.MvcCoreBuilder .AddApplicationPart(typeof(ASFBuilder).Assembly) .AddApiExplorer(); builder.Services.AddASFCore(startupAction); builder.Services.AddSingleton <OcelotMiddlewareConfigurationDelegate>(ASFMiddlewareConfigurationProvider.Get); return(builder); }
public static IOcelotBuilder AddGrpcHttpGateway(this IOcelotBuilder builder) { //var bases = AppDomain.CurrentDomain.BaseDirectory; return(builder.AddGrpcHttpGateway(new GrpcHttpGatewayConfiguration { PluginMonitor = true, ProtoMonitor = true })); }
public static IOcelotBuilder AddConfigStoredInMySql(this IOcelotBuilder builder, string apiGatewayKey) { builder.Services.AddHostedService <FileConfigurationPoller>(); builder.Services.AddSingleton <IFileConfigurationRepository>(sp => { return(new MySqlFileConfigurationRepository(sp, apiGatewayKey)); }); return(builder); }
public static IOcelotBuilder AddEureka(this IOcelotBuilder builder) { var service = builder.Services.First(x => x.ServiceType == typeof(IConfiguration)); var configuration = (IConfiguration)service.ImplementationInstance; builder.Services.AddDiscoveryClient(configuration); builder.Services.AddSingleton <ServiceDiscoveryFinderDelegate>(EurekaProviderFactory.Get); builder.Services.AddSingleton <OcelotMiddlewareConfigurationDelegate>(EurekaMiddlewareConfigurationProvider.Get); return(builder); }
public static IOcelotBuilder AddConfigStoredInRedis(this IOcelotBuilder builder, string apiGatewayKey, string redisConnectionString) { builder.Services.AddSingleton <RedisClient>(); builder.Services.AddHostedService <FileConfigurationPoller>(); builder.Services.AddSingleton <IFileConfigurationRepository>(sp => { return(new RedisFileConfigurationRepository(sp.GetRequiredService <RedisClient>(), apiGatewayKey, redisConnectionString)); }); return(builder); }
/// <summary> /// 添加默认的注入方式,所有需要传入的参数都是用默认值 /// </summary> /// <param name="builder"></param> /// <returns></returns> public static IOcelotBuilder AddAhphOcelot(this IOcelotBuilder builder, Action <AhphOcelotConfiguration> option) { builder.Services.Configure(option); //配置信息 builder.Services.AddSingleton( resolver => resolver.GetRequiredService <IOptions <AhphOcelotConfiguration> >().Value); //配置文件仓储注入 builder.Services.AddSingleton <IFileConfigurationRepository, SqlServerFileConfigurationRepository>(); return(builder); }
public static IOcelotBuilder WithReplaceHandler(this IOcelotBuilder builder) { if (!_withReplaceHandler) { builder .WithRouteExtensions(); builder.AddDelegatingHandler <ReplaceHandler>(); _withReplaceHandler = true; } return(builder); }
public static void AddRedisCache(this IOcelotBuilder builder, string connectionString, string instanceName = null) { builder.Services.AddTransient <ICachedResponseSerializer, CachedResponseSerializer>(); builder.Services.AddStackExchangeRedisCache(x => { x.InstanceName = instanceName ?? DateTime.UtcNow.ToString(CultureInfo.InvariantCulture); x.Configuration = connectionString; }); builder.Services.AddSingleton <IOcelotCache <CachedResponse>, RedisCache>(); }
private void WhenISetUpOcelotServices() { try { _ocelotBuilder = _services.AddOcelot(_configRoot); } catch (Exception e) { _ex = e; } }
public static IOcelotBuilder WithRouteExtensions(this IOcelotBuilder builder, string configKey = "RouteExtensions") { if (!_initialized) { builder.Services.AddSingleton <IFileConfigurationRepository, DiskFileConfigurationRepositoryExtended>(); builder.Services.AddSingleton <IFileConfigurationRepositoryExtended, DiskFileConfigurationRepositoryExtended>(); builder.Services.Configure <RouteExtensions>(builder.Configuration.GetSection(configKey)); _initialized = true; } return(builder); }
private void WhenISetUpOcelotServicesWithoutConfig() { try { _ocelotBuilder = _services.AddOcelot(); } catch (Exception e) { _ex = e; } }
public static IOcelotBuilder AddAbpOcelot(this IOcelotBuilder builder, Action <ConfigCacheOptions> option) { builder.Services.Configure(option); builder.Services.AddSingleton( resolver => resolver.GetRequiredService <IOptions <ConfigCacheOptions> >().Value); builder.Services.AddSingleton(DataBaseConfigurationProvider.Get); builder.Services.AddSingleton <IFileConfigurationRepository, FileConfigurationRepository>(); return(builder); }
/// <summary> /// Store OcelotConfiguration in EntityFramework /// </summary> /// <param name="builder">the OcelotBuilder</param> /// <param name="optionsAction">Ocelot DbContext optionsAction</param> /// <param name="repoOptionsAction">repoOptionsAction</param> /// <returns>the OcelotBuilder</returns> public static IOcelotBuilder StoreConfigurationInEntityFramework(this IOcelotBuilder builder, Action <DbContextOptionsBuilder> optionsAction, Action <EFConfigurationRepositoryOptions> repoOptionsAction) { if (null != repoOptionsAction) { builder.Services.Configure(repoOptionsAction); } builder.StoreConfigurationInEntityFramework(optionsAction); return(builder); }