public static void AddHystrixCommand <TService>(this IServiceCollection services, IHystrixCommandGroupKey groupKey, IHystrixCommandKey commandKey, IConfiguration config) where TService : class { var strategy = HystrixPlugins.OptionsStrategy; var dynOpts = strategy.GetDynamicOptions(config); IHystrixCommandOptions opts = new HystrixCommandOptions(commandKey, null, dynOpts) { GroupKey = groupKey }; services.AddTransient <TService>((p) => (TService)ActivatorUtilities.CreateInstance(p, typeof(TService), opts)); }
public static void AddHystrixCommand <TService, TImplementation>(this IServiceCollection services, IHystrixCommandGroupKey groupKey, IHystrixCommandKey commandKey, IConfiguration config) where TService : class where TImplementation : class, TService { if (services == null) { throw new ArgumentNullException(nameof(services)); } if (groupKey == null) { throw new ArgumentNullException(nameof(groupKey)); } if (commandKey == null) { throw new ArgumentNullException(nameof(commandKey)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } var strategy = HystrixPlugins.OptionsStrategy; var dynOpts = strategy.GetDynamicOptions(config); var threadPoolKey = HystrixThreadPoolKeyDefault.AsKey(groupKey.Name); IHystrixCommandOptions opts = new HystrixCommandOptions(commandKey, null, dynOpts) { GroupKey = groupKey, ThreadPoolKey = threadPoolKey }; opts.ThreadPoolOptions = new HystrixThreadPoolOptions(threadPoolKey, null, dynOpts); services.AddTransient <TService, TImplementation>((p) => (TImplementation)ActivatorUtilities.CreateInstance(p, typeof(TImplementation), opts)); }