Ejemplo n.º 1
0
 public static void Configure(this DbContextOptionsBuilder optionsBuilder,
                              BehlogSetting setting,
                              IServiceProvider provider)
 {
     optionsBuilder.UseSqlServer(setting.GetConnectionString(),
                                 __ => {
         __.CommandTimeout((int)TimeSpan.FromMinutes(3).TotalSeconds);
         __.EnableRetryOnFailure();
         __.MigrationsAssembly(typeof(SqlServerContextFactory).Assembly.FullName);
     });
     optionsBuilder.UseInternalServiceProvider(provider);
     optionsBuilder.AddInterceptors(new PersianDataCommandInterceptor());
 }
        public static IServiceCollection AddDatabaseCacheStores(
            this IServiceCollection services,
            BehlogSetting setting
            )
        {
            var cookieOptions = setting.CookieOptions;

            if (!cookieOptions.UseDistributedCacheTicketStore)
            {
                return(services);
            }

            switch (setting.DbType)
            {
            case AppDatabaseType.InMemory:
                services.AddMemoryCache();
                services.AddScoped <ITicketStore, MemoryCacheTicketStore>();
                break;

            case AppDatabaseType.LocalDb:
            case AppDatabaseType.SqlServer:
                services.AddDistributedSqlServerCache(_ => {
                    var cachOptions    = cookieOptions.DistributedSqlServerCacheOptions;
                    _.ConnectionString = string.IsNullOrWhiteSpace(cachOptions.ConnectionString)
                            ? setting.GetConnectionString()
                            : cachOptions.ConnectionString;
                    _.SchemaName = cachOptions.SchemaName;
                    _.TableName  = cachOptions.TableName;
                });
                services.AddScoped <ITicketStore, DistributedCacheTicketStore>();
                break;

            case AppDatabaseType.SQLite:
                services.AddMemoryCache();
                services.AddScoped <ITicketStore, MemoryCacheTicketStore>();
                break;

            default:
                throw new NotSupportedException("Please set the value of [DbType] property in appsettings.json file correctly.");
            }

            return(services);
        }