Unverified Commit 718954a7 authored by JEN's avatar JEN Committed by GitHub

implemented retrieval of connection string from appsettings.json rather than being hardcoded (#111)

Thanks!
parent c902b812
...@@ -6,8 +6,8 @@ namespace CleanArchitecture.Infrastructure ...@@ -6,8 +6,8 @@ namespace CleanArchitecture.Infrastructure
{ {
public static class StartupSetup public static class StartupSetup
{ {
public static void AddDbContext(this IServiceCollection services) => public static void AddDbContext(this IServiceCollection services, string connectionString) =>
services.AddDbContext<AppDbContext>(options => services.AddDbContext<AppDbContext>(options =>
options.UseSqlite("Data Source=database.sqlite")); // will be created in web project root options.UseSqlite(connectionString)); // will be created in web project root
} }
} }
...@@ -31,7 +31,10 @@ namespace CleanArchitecture.Web ...@@ -31,7 +31,10 @@ namespace CleanArchitecture.Web
options.MinimumSameSitePolicy = SameSiteMode.None; options.MinimumSameSitePolicy = SameSiteMode.None;
}); });
services.AddDbContext(); string connectionString = Configuration.GetConnectionString("SqlLiteConnection"); //Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext(Configuration.GetConnectionString(connectionString));
services.AddControllersWithViews().AddNewtonsoftJson(); services.AddControllersWithViews().AddNewtonsoftJson();
services.AddRazorPages(); services.AddRazorPages();
......
{ {
"ConnectionStrings": { "ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\v11.0;Database=cleanarchitecture;Trusted_Connection=True;MultipleActiveResultSets=true" "DefaultConnection": "Server=(localdb)\\v11.0;Database=cleanarchitecture;Trusted_Connection=True;MultipleActiveResultSets=true",
"SqlLiteConnection": "Data Source=database.sqlite"
}, },
"Logging": { "Logging": {
"IncludeScopes": false, "IncludeScopes": false,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment