protected internal override void AddInternal(IDistributedCacheBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            base.AddInternal(builder);

            builder.Services.AddDbContextFactory <SqliteCacheContext>(optionsBuilder =>
            {
                optionsBuilder.UseSqlite(
                    builder.Configuration.GetConnectionString(this.ConnectionStringName),
                    options =>
                {
                    if (this.MigrationsAssembly != null)
                    {
                        options.MigrationsAssembly(this.MigrationsAssembly);
                    }
                });
            });

            builder.Services.AddSingleton <IDistributedCache, SqliteCache>();

            builder.Services.Configure <SqliteCacheOptions>(options =>
            {
                this.Options?.Bind(options);
            });
        }
        protected internal override void AddInternal(IDistributedCacheBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var sqlServerCacheOptions = new SqlServerCacheOptions();

            this.BindSqlServerCacheOptions(builder.Configuration, sqlServerCacheOptions);

            builder.Services.AddDbContext <SqlServerCacheContext>(optionsBuilder =>
            {
                optionsBuilder.UseSqlServer(sqlServerCacheOptions.ConnectionString,
                                            options =>
                {
                    if (this.MigrationsAssembly != null)
                    {
                        options.MigrationsAssembly(this.MigrationsAssembly);
                    }
                }
                                            );
            });

            builder.Services.AddDistributedSqlServerCache(options =>
            {
                this.BindSqlServerCacheOptions(builder.Configuration, options);
            });
        }
        protected internal override void AddInternal(IDistributedCacheBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.TryAddSingleton <ISystemClock, SystemClock>();
        }
Пример #4
0
        protected internal override void AddInternal(IDistributedCacheBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddDistributedMemoryCache(options =>
            {
                this.Options?.Bind(options);
            });
        }
        public virtual void Add(IDistributedCacheBuilder builder)
        {
            try
            {
                if (builder == null)
                {
                    throw new ArgumentNullException(nameof(builder));
                }

                if (this.RemoveRegisteredService)
                {
                    builder.Services.Remove <IDistributedCache>();
                }

                this.AddInternal(builder);
            }
            catch (Exception exception)
            {
                throw new InvalidOperationException($"Could not add distributed cache with options of type \"{this.GetType()}\".", exception);
            }
        }
Пример #6
0
        protected internal override void AddInternal(IDistributedCacheBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            base.AddInternal(builder);

            var sqlServerOptions = new SqlServerOptions
            {
                ConnectionStringName = this.ConnectionStringName,
                MigrationsAssembly   = this.MigrationsAssembly,
                Options = this.Options
            };

            var sqlServerCacheOptions = new SqlServerCacheOptions();

            sqlServerOptions.BindSqlServerCacheOptions(builder.Configuration, sqlServerCacheOptions);

            builder.Services.AddDbContextFactory <SqlServerCacheContext>(optionsBuilder =>
            {
                optionsBuilder.UseSqlServer(sqlServerCacheOptions.ConnectionString,
                                            options =>
                {
                    if (this.MigrationsAssembly != null)
                    {
                        options.MigrationsAssembly(this.MigrationsAssembly);
                    }
                });
            });

            builder.Services.AddSingleton <IDistributedCache, DateTimeOffsetCacheMock>();

            builder.Services.Configure <DateTimeOffsetCacheOptionsMock>(options =>
            {
                this.Options?.Bind(options);
            });
        }
        protected internal override void AddInternal(IDistributedCacheBuilder builder)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            builder.Services.AddDistributedRedisCache(options =>
            {
                this.Options?.Bind(options);

                var connectionString = builder.Configuration.GetConnectionString(this.ConnectionStringName);

                if (options.Configuration == null && connectionString != null)
                {
                    options.Configuration = connectionString;
                }

                if (options.Configuration == null && options.ConfigurationOptions == null)
                {
                    options.ConfigurationOptions = new ConfigurationOptions();
                }

                if (options.ConfigurationOptions == null)
                {
                    return;
                }

                var endPointsSection = builder.Configuration.GetSection($"{builder.ConfigurationKey}:{nameof(this.Options)}:{nameof(options.ConfigurationOptions)}:{nameof(options.ConfigurationOptions.EndPoints)}");
                var endPoints        = new Dictionary <string, int>();
                endPointsSection?.Bind(endPoints);

                foreach (var endPoint in endPoints)
                {
                    options.ConfigurationOptions.EndPoints.Add(endPoint.Key, endPoint.Value);
                }
            });
        }
Пример #8
0
 protected internal override void AddInternal(IDistributedCacheBuilder builder)
 {
     // Do nothing.
 }
 protected internal abstract void AddInternal(IDistributedCacheBuilder builder);