Esempio n. 1
0
        private static void AddDistributedSqlServerCache(IServiceCollection services,
                                                         DistributedCacheConfiguration distributedCacheConfiguration)
        {
            if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheSqlConnectionString))
            {
                throw new InvalidOperationException(
                          $"'{nameof(DistributedCacheConfiguration.CacheSqlConnectionString)}' configuration " +
                          $"is required for 'StorageType.SqlServer'.");
            }

            if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheSqlSchemaName))
            {
                throw new InvalidOperationException(
                          $"'{nameof(DistributedCacheConfiguration.CacheSqlSchemaName)}' configuration " +
                          $"is required for 'StorageType.SqlServer'.");
            }

            if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheSqlTableName))
            {
                throw new InvalidOperationException(
                          $"'{nameof(DistributedCacheConfiguration.CacheSqlTableName)}' configuration " +
                          $"is required for 'StorageType.SqlServer'.");
            }

            services.AddDistributedSqlServerCache(options =>
            {
                options.ConnectionString = distributedCacheConfiguration.CacheSqlConnectionString;
                options.SchemaName       = distributedCacheConfiguration.CacheSqlSchemaName;
                options.TableName        = distributedCacheConfiguration.CacheSqlTableName;
            });
        }
Esempio n. 2
0
 private static void AddDistributedMemoryCache(IServiceCollection services,
                                               DistributedCacheConfiguration distributedCacheConfiguration)
 {
     services.AddDistributedMemoryCache(options =>
     {
         options.SizeLimit = distributedCacheConfiguration.MemorySizeLimit;
     });
 }
Esempio n. 3
0
        public PersonService(ILogger <PersonService> logger,
                             IPersonRepository personRepository,
                             IDistributedCache cacheClient,
                             DistributedCacheConfiguration distributedCacheConfig

                             )
        {
            _personRepository       = personRepository;
            _logger                 = logger;
            _cacheClient            = cacheClient;
            _distributedCacheConfig = distributedCacheConfig;
        }
Esempio n. 4
0
 public S3FileSchemaProvider(IS3Gateway s3Service,
                             IWebHostEnvironment environment,
                             IDistributedCacheWrapper distributedCacheWrapper,
                             IConfiguration configuration,
                             IOptions <DistributedCacheConfiguration> distributedCacheConfiguration,
                             IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration,
                             ILogger <ISchemaProvider> logger)
 {
     _s3Gateway                               = s3Service;
     _environment                             = environment;
     _configuration                           = configuration;
     _logger                                  = logger;
     _distributedCacheWrapper                 = distributedCacheWrapper;
     _distributedCacheConfiguration           = distributedCacheConfiguration.Value;
     _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value;
 }
Esempio n. 5
0
 public SchemaFactory(IDistributedCacheWrapper distributedCache,
                      ISchemaProvider schemaProvider,
                      ILookupSchemaTransformFactory lookupSchemaFactory,
                      IReusableElementSchemaTransformFactory reusableElementSchemaFactory,
                      IOptions <DistributedCacheConfiguration> distributedCacheConfiguration,
                      IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration,
                      IConfiguration configuration)
 {
     _distributedCache                        = distributedCache;
     _schemaProvider                          = schemaProvider;
     _lookupSchemaFactory                     = lookupSchemaFactory;
     _reusableElementSchemaFactory            = reusableElementSchemaFactory;
     _distributedCacheConfiguration           = distributedCacheConfiguration.Value;
     _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value;
     _configuration = configuration;
 }
Esempio n. 6
0
        public static IServiceCollection AddOtcDistributedCache(this IServiceCollection services,
                                                                DistributedCacheConfiguration distributedCacheConfiguration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (distributedCacheConfiguration == null)
            {
                throw new ArgumentNullException(nameof(distributedCacheConfiguration));
            }

            services.AddOtcCaching(distributedCacheConfiguration);

            if (distributedCacheConfiguration.CacheEnabled)
            {
                switch (distributedCacheConfiguration.CacheStorageType)
                {
                case StorageType.SqlServer:
                    AddDistributedSqlServerCache(services, distributedCacheConfiguration);

                    break;

                case StorageType.Redis:
                    AddDistributedRedisCache(services, distributedCacheConfiguration);

                    break;

                case StorageType.Memory:
                    AddDistributedMemoryCache(services, distributedCacheConfiguration);

                    break;

                default:
                    throw new InvalidOperationException("Could not determine caching storage type," +
                                                        " please verify StorageType configuration property.");
                }
            }

            return(services);
        }
Esempio n. 7
0
 public SchemaFactory(IDistributedCacheWrapper distributedCache,
                      ISchemaProvider schemaProvider,
                      ILookupSchemaTransformFactory lookupSchemaFactory,
                      IReusableElementSchemaTransformFactory reusableElementSchemaFactory,
                      IOptions <DistributedCacheConfiguration> distributedCacheConfiguration,
                      IOptions <DistributedCacheExpirationConfiguration> distributedCacheExpirationConfiguration,
                      IConfiguration configuration,
                      IFormSchemaIntegrityValidator formSchemaIntegrityValidator,
                      IEnumerable <IUserPageTransformFactory> userPageTransformFactories)
 {
     _distributedCache                        = distributedCache;
     _schemaProvider                          = schemaProvider;
     _lookupSchemaFactory                     = lookupSchemaFactory;
     _reusableElementSchemaFactory            = reusableElementSchemaFactory;
     _distributedCacheConfiguration           = distributedCacheConfiguration.Value;
     _distributedCacheExpirationConfiguration = distributedCacheExpirationConfiguration.Value;
     _configuration = configuration;
     _formSchemaIntegrityValidator = formSchemaIntegrityValidator;
     _userPageTransformFactories   = userPageTransformFactories;
 }
Esempio n. 8
0
        private static void AddDistributedRedisCache(IServiceCollection services,
                                                     DistributedCacheConfiguration distributedCacheConfiguration)
        {
            if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheRedisInstanceName))
            {
                throw new InvalidOperationException(
                          $"'{nameof(DistributedCacheConfiguration.CacheRedisInstanceName)}' configuration " +
                          $"is required for 'StorageType.Redis'.");
            }

            if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheRedisConfiguration))
            {
                throw new InvalidOperationException(
                          $"'{nameof(DistributedCacheConfiguration.CacheRedisConfiguration)}' configuration " +
                          $"is required for 'StorageType.Redis'.");
            }

            services.AddStackExchangeRedisCache(options =>
            {
                options.Configuration = distributedCacheConfiguration.CacheRedisConfiguration;
                options.InstanceName  = distributedCacheConfiguration.CacheRedisInstanceName;
            });
        }
Esempio n. 9
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();


            var distributedCacheConfig = new DistributedCacheConfiguration();

            Configuration.GetSection(DistributedCacheConfiguration.ConfigurationSectionKey).Bind(distributedCacheConfig);
            if (distributedCacheConfig.DistributedCacheEnabled)
            {
                services.AddDistributedRedisCache(options =>
                {
                    options.Configuration = Configuration.GetConnectionString("Redis");
                    options.InstanceName  = "User_";
                });
            }

            services.AddScoped(typeof(DistributedCacheConfiguration), p => { return(distributedCacheConfig); });
            string sourceApiUrl     = Configuration[SourceApiUrlKey];
            var    sourceApiTimeout = long.Parse(Configuration[SourceApiTimeoutInSecondsKey]);

            services.AddScoped(typeof(IPersonRepository), p => { return(new PersonApiRepository(sourceApiUrl, sourceApiTimeout)); });
            services.AddScoped(typeof(IPersonService), typeof(PersonService));
        }
Esempio n. 10
0
        public static IServiceCollection AddOtcDistributedCache(this IServiceCollection services, DistributedCacheConfiguration distributedCacheConfiguration)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            if (distributedCacheConfiguration == null)
            {
                throw new ArgumentNullException(nameof(distributedCacheConfiguration));
            }

            services.AddOtcCaching(distributedCacheConfiguration);

            if (distributedCacheConfiguration.CacheEnabled)
            {
                switch (distributedCacheConfiguration.CacheStorageType)
                {
                case StorageType.SqlServer:

                    if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheSqlConnectionString))
                    {
                        throw new InvalidOperationException($"'{nameof(DistributedCacheConfiguration.CacheSqlConnectionString)}' configuration is required for 'StorageType.SqlServer'.");
                    }

                    if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheSqlSchemaName))
                    {
                        throw new InvalidOperationException($"'{nameof(DistributedCacheConfiguration.CacheSqlSchemaName)}' configuration is required for 'StorageType.SqlServer'.");
                    }

                    if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheSqlTableName))
                    {
                        throw new InvalidOperationException($"'{nameof(DistributedCacheConfiguration.CacheSqlTableName)}' configuration is required for 'StorageType.SqlServer'.");
                    }

                    services.AddDistributedSqlServerCache(options =>
                    {
                        options.ConnectionString = distributedCacheConfiguration.CacheSqlConnectionString;
                        options.SchemaName       = distributedCacheConfiguration.CacheSqlSchemaName;
                        options.TableName        = distributedCacheConfiguration.CacheSqlTableName;
                    });

                    break;

                case StorageType.Redis:

                    if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheRedisInstanceName))
                    {
                        throw new InvalidOperationException($"'{nameof(DistributedCacheConfiguration.CacheRedisInstanceName)}' configuration is required for 'StorageType.Redis'.");
                    }

                    if (string.IsNullOrEmpty(distributedCacheConfiguration.CacheRedisConfiguration))
                    {
                        throw new InvalidOperationException($"'{nameof(DistributedCacheConfiguration.CacheRedisConfiguration)}' configuration is required for 'StorageType.Redis'.");
                    }

                    services.AddDistributedRedisCache(options =>
                    {
                        options.Configuration = distributedCacheConfiguration.CacheRedisConfiguration;
                        options.InstanceName  = distributedCacheConfiguration.CacheRedisInstanceName;
                    });

                    break;

                case StorageType.Memory:
                    services.AddDistributedMemoryCache(options =>
                    {
                        options.SizeLimit = distributedCacheConfiguration.MemorySizeLimit;
                    });

                    break;

                default:
                    throw new InvalidOperationException("Could not determine caching storage type, please verify StorageType configuration property.");
                }
            }

            return(services);
        }