我们创建了一个"on-prem"网络应用程序,并且我被指派创建该应用程序的安装程序,使用户可以编程选择SQLite或SQL Server实现。我对如何做此项任务一无所知,并且没有找到任何具有清晰指导方向的好文章。
我在我的
我在我的
Startup.cs
文件中编写了以下代码,以在我的appsettings.json
文件中选择两个连接字符串之间进行选择。是否有人知道创建/实现安装程序的最佳方法?是否有开源解决方案可处理此类问题?我在这个问题上感到很迷茫....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;
}