Beispiel #1
0
        public static IServiceCollection AddBeQueueSerivce <TServiceFactory, TService>(this IServiceCollection services,
                                                                                       Action <PoolSetting> setting = null
                                                                                       )
            where TServiceFactory : ExecutionServiceFactory <TService>
            where TService : IDisposable
        {
            services.AddSingleton <TServiceFactory>();
            services.AddSingleton(sp =>
            {
                var option = new PoolSetting();
                setting?.Invoke(option);
                var factory = sp.GetService <TServiceFactory>();
                return(new ExecutionPool <TServiceFactory, TService>(factory, option));
            });

            return(services);
        }
Beispiel #2
0
        public ExecutionPool(TFatory factoryService, PoolSetting setting)
        {
            if (factoryService == null)
            {
                throw new ArgumentNullException(nameof(factoryService));
            }

            _setting = setting ?? throw new ArgumentNullException(nameof(setting));
            for (var i = 0; i < setting.PoolSize; i++)
            {
                _pools.Add(new ExecuteQueue <TFatory, TService>(factoryService)
                {
                    ExecuteIntervalTime = setting.ExecuteIntervalTime,
                    ExecuteTimeout      = setting.ExecuteTimeout
                });
            }
        }