public void ConfigureServices(IServiceCollection services) { var vbConfig = new VBConfig(Configuration.GetValue <string>("VBCookieSalt")); services.AddVBDbContext <VBCache>(vbConfig, Configuration.GetConnectionString("VBForum"), ServerType.MariaDb); services.AddVBManagers(vbConfig.CookieSalt); services.AddMvc(); }
public VBSessionManager(VBDbContext db, VBUserManager userManager, VBSettingsManager settingsManager, VBConfig vbConfig, IHttpContextAccessor contextAccessor, IVBCache cache) { this.db = db; this.userManager = userManager; this.settingsManager = settingsManager; this.vbConfig = vbConfig; this.contextAccessor = contextAccessor; this.cache = cache; }
public static void AddVBDbContext <ICachingProvider>(this IServiceCollection services, VBConfig vbConfig, string connectionString, ServerType serverType = ServerType.MariaDb, bool sensitiveDataLogging = false) where ICachingProvider : IVBCache { services.AddSingleton(vbConfig); services.AddDbContext <VBDbContext>(options => { options.UseMySql(connectionString); if (sensitiveDataLogging) { options.EnableSensitiveDataLogging(); } }, ServiceLifetime.Scoped); // For light managers services.AddScoped(x => new MySqlConnection(connectionString)); if (typeof(ICachingProvider) == typeof(VBCache)) { services.AddMemoryCache(); } // https://stackoverflow.com/a/33567396/3276634 services.AddScoped(typeof(IVBCache), typeof(ICachingProvider)); }