【发布时间】:2020-08-14 21:31:55
【问题描述】:
我们创建了一个“本地”网络应用程序,我的任务是为该应用程序创建一个安装程序,该安装程序将以编程方式允许用户在 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;
}
【问题讨论】:
-
到目前为止你看到了什么?有一些开源解决方案,例如WiX toolset, NSIS, ... 您应该也可以使用安装程序boostrap SQL Server
-
假设这是您要分发的 SASS 产品,您是否考虑过创建 2 个 docker 容器,一个用于 SQLite,一个用于 SQL Server?并通过 docker 分发?
标签: c# .net sql-server deployment