We created an "on-prem" web app and I have been tasked with creating an installer for the app that will programmatically allow the user to choose between a SQLite or SQL Server implementation. I have zero clue on how to do this and have not found any good articles with clear direction.
All I have done is write the following code in my Startup.cs
file to choose between two connection strings located in my appsettings.json
file. Does anyone know the best way to create/implement an installer? Are there open source solutions for this kind of thing? I feel so lost on this one....
protected virtual IServiceCollection ConfigureDbContext(IServiceCollection services)
{
var isSqlServerConnection = Configuration.GetValue<bool>("UseSql");
if (isSqlServerConnection)
{
services.AddDbContext<SecurityDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("Default")).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll),
ServiceLifetime.Transient);
services.AddDbContext<StorageContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("Default")).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking),
ServiceLifetime.Transient);
}
else
{
services.AddDbContext<SecurityDbContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("Sqlite")).UseQueryTrackingBehavior(QueryTrackingBehavior.TrackAll),
ServiceLifetime.Transient);
services.AddDbContext<StorageContext>(options =>
options.UseSqlite(Configuration.GetConnectionString("Sqlite")).UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking)
, ServiceLifetime.Transient);
}
return services;
}