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
{
public static class StartupSetup
{
public static void AddDbContext(this IServiceCollection services) =>
public static void AddDbContext(this IServiceCollection services, string connectionString) =>
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,24 +31,27 @@ namespace CleanArchitecture.Web
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddDbContext();
string connectionString = Configuration.GetConnectionString("SqlLiteConnection"); //Configuration.GetConnectionString("DefaultConnection");
services.AddDbContext(Configuration.GetConnectionString(connectionString));
services.AddControllersWithViews().AddNewtonsoftJson();
services.AddRazorPages();
services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" }));
// add list services for diagnostic purposes - see https://github.com/ardalis/AspNetCoreStartupServices
services.Configure<ServiceConfig>(config =>
{
config.Services = new List<ServiceDescriptor>(services);
// add list services for diagnostic purposes - see https://github.com/ardalis/AspNetCoreStartupServices
services.Configure<ServiceConfig>(config =>
{
config.Services = new List<ServiceDescriptor>(services);
// optional - default path to view services is /listallservices - recommended to choose your own path
config.Path = "/listservices";
});
// optional - default path to view services is /listallservices - recommended to choose your own path
config.Path = "/listservices";
});
//return ContainerSetup.InitializeWeb(Assembly.GetExecutingAssembly(), services);
}
//return ContainerSetup.InitializeWeb(Assembly.GetExecutingAssembly(), services);
}
public void ConfigureContainer(ContainerBuilder builder)
{
......@@ -61,8 +64,8 @@ namespace CleanArchitecture.Web
if (env.EnvironmentName == "Development")
{
app.UseDeveloperExceptionPage();
app.UseShowAllServicesMiddleware();
}
app.UseShowAllServicesMiddleware();
}
else
{
app.UseExceptionHandler("/Home/Error");
......
{
"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": {
"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