Ejemplo n.º 1
0
            static BoundedObjectPoolOptions GetObjectPoolOptions(IServiceProvider serviceProvider)
            {
                var options = serviceProvider.GetRequiredService <IOptions <ResponseCachingExecutingLockOptions> >().Value;

                var boundedObjectPoolOptions = new BoundedObjectPoolOptions()
                {
                    MaximumPooled   = options.MaximumExecutingLockPooled,
                    MinimumRetained = options.MinimumExecutingLockRetained,
                    RecycleInterval = options.ExecutingLockRecycleInterval,
                };

                return(boundedObjectPoolOptions);
            }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加<see cref="IExecutingLockPool{TCachePayload}"/>
        /// </summary>
        /// <param name="services"></param>
        private static void AddExecutingLockPool(this IServiceCollection services)
        {
            services.TryAddSingleton(services =>
            {
                var options = services.GetRequiredService <IOptions <ResponseCachingExecutingLockOptions> >().Value;

                var boundedObjectPoolOptions = new BoundedObjectPoolOptions()
                {
                    MaximumPooled   = options.MaximumSemaphorePooled,
                    MinimumRetained = options.MinimumSemaphoreRetained,
                    RecycleInterval = options.SemaphoreRecycleInterval,
                };

                var semaphorePool = BoundedObjectPool.Create(new SinglePassSemaphoreLifecycleExecutor(), boundedObjectPoolOptions);

                return((INakedBoundedObjectPool <SemaphoreSlim>)semaphorePool);
            });

            services.TryAddSingleton(typeof(ExclusiveExecutingLockLifecycleExecutor <>));
            services.TryAddSingleton(typeof(SharedExecutingLockLifecycleExecutor <>));

            services.TryAddSingleton(serviceProvider => CreateSharedExecutingLockPool(serviceProvider));
            services.TryAddSingleton(serviceProvider => CreateExclusiveExecutingLockPool(serviceProvider));