Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CleanArchitecture
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CleanArchitecture
Commits
718954a7
Unverified
Commit
718954a7
authored
Apr 26, 2020
by
JEN
Committed by
GitHub
Apr 26, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implemented retrieval of connection string from appsettings.json rather than being hardcoded (#111)
Thanks!
parent
c902b812
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
15 deletions
+19
-15
StartupSetup.cs
src/CleanArchitecture.Infrastructure/StartupSetup.cs
+2
-2
Startup.cs
src/CleanArchitecture.Web/Startup.cs
+15
-12
appsettings.json
src/CleanArchitecture.Web/appsettings.json
+2
-1
No files found.
src/CleanArchitecture.Infrastructure/StartupSetup.cs
View file @
718954a7
...
...
@@ -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
}
}
src/CleanArchitecture.Web/Startup.cs
View file @
718954a7
...
...
@@ -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"
);
...
...
src/CleanArchitecture.Web/appsettings.json
View file @
718954a7
{
"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
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment