Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 7704705

Browse files
Read connection string from app settings.json file
1 parent 1d5b563 commit 7704705

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

‎Webgentle.BookStore/Webgentle.BookStore/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"commandName": "IISExpress",
1313
"launchBrowser": true,
1414
"environmentVariables": {
15-
"ASPNETCORE_ENVIRONMENT": "Production"
15+
"ASPNETCORE_ENVIRONMENT": "Development"
1616
}
1717
},
1818
"Webgentle.BookStore": {

‎Webgentle.BookStore/Webgentle.BookStore/Startup.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Microsoft.AspNetCore.Hosting;
88
using Microsoft.AspNetCore.Http;
99
using Microsoft.EntityFrameworkCore;
10+
using Microsoft.Extensions.Configuration;
1011
using Microsoft.Extensions.DependencyInjection;
1112
using Microsoft.Extensions.FileProviders;
1213
using Microsoft.Extensions.Hosting;
@@ -16,13 +17,20 @@
1617
namespace Webgentle.BookStore
1718
{
1819
public class Startup
19-
{
20+
{
21+
private readonly IConfiguration _configuration;
22+
23+
public Startup(IConfiguration configuration)
24+
{
25+
_configuration = configuration;
26+
}
27+
2028
// This method gets called by the runtime. Use this method to add services to the container.
2129
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
2230
public void ConfigureServices(IServiceCollection services)
2331
{
2432
services.AddDbContext<BookStoreContext>(
25-
options => options.UseSqlServer("Server=.;Database=BookStore;Integrated Security=True;"));
33+
options => options.UseSqlServer(_configuration.GetConnectionString("DefaultConnection")));
2634

2735
services.AddControllersWithViews();
2836
#if DEBUG

‎Webgentle.BookStore/Webgentle.BookStore/appsettings.Development.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"Microsoft.Hosting.Lifetime": "Information"
77
}
88
},
9-
"AppName": "Book store from development json file",
9+
"AppName": "Book store",
1010
"infoObj": {
1111
"key1": "key 1 value d",
1212
"key2": "key 2 value d",

‎Webgentle.BookStore/Webgentle.BookStore/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"Microsoft.Hosting.Lifetime": "Information"
77
}
88
},
9+
"ConnectionStrings": {
10+
"DefaultConnection": "Server=.;Database=BookStore;Integrated Security=True;"
11+
},
912
"AllowedHosts": "*",
1013
"AppName": "Book store App",
1114
"infoObj": {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /