File tree Expand file tree Collapse file tree 5 files changed +34
-5
lines changed
NetCoreKit.Infrastructure.EfCore.MySql
NetCoreKit.Infrastructure Expand file tree Collapse file tree 5 files changed +34
-5
lines changed Original file line number Diff line number Diff line change 11using System . Linq ;
2- using Microsoft . Extensions . Configuration ;
32using Microsoft . Extensions . Options ;
43using NetCoreKit . Infrastructure . EfCore . Db ;
54
65namespace NetCoreKit . Infrastructure . EfCore . MySql
76{
87 public sealed class DatabaseConnectionStringFactory : IDatabaseConnectionStringFactory
98 {
10- private readonly IConfiguration _config ;
119 private readonly DbOptions _dbOption ;
1210
13- public DatabaseConnectionStringFactory ( IConfiguration config , IOptions < DbOptions > options )
11+ public DatabaseConnectionStringFactory ( )
12+ {
13+ var config = ConfigurationHelper . GetConfiguration ( ) ;
14+ var dbSection = config . GetSection ( "Features:EfCore:MySqlDb" ) ;
15+ _dbOption = new DbOptions {
16+ ConnString = dbSection [ "ConnString" ] ,
17+ FQDN = dbSection [ "FQDN" ] ,
18+ Database = dbSection [ "Database" ] ,
19+ DbInfo = dbSection [ "DbInfo" ] ,
20+ UserName = dbSection [ "UserName" ] ,
21+ Password = dbSection [ "Password" ]
22+ } ;
23+ }
24+
25+ public DatabaseConnectionStringFactory ( IOptions < DbOptions > options )
1426 {
15- _config = config ;
1627 _dbOption = options . Value ;
1728 }
1829
Original file line number Diff line number Diff line change 11using System ;
22using System . Collections . Generic ;
3+ using System . IO ;
34using System . Linq ;
45using System . Reflection ;
56using Microsoft . Extensions . Configuration ;
@@ -32,4 +33,19 @@ public static IEnumerable<Assembly> LoadApplicationAssemblies(this IConfiguratio
3233 return apps ;
3334 }
3435 }
36+
37+ public class ConfigurationHelper
38+ {
39+ public static IConfigurationRoot GetConfiguration ( string basePath = null )
40+ {
41+ basePath = basePath ?? Directory . GetCurrentDirectory ( ) ;
42+ var builder = new ConfigurationBuilder ( )
43+ . SetBasePath ( basePath )
44+ . AddJsonFile ( "appsettings.json" )
45+ . AddJsonFile ( $ "appsettings.{ Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) } .json", true )
46+ . AddEnvironmentVariables ( ) ;
47+
48+ return builder . Build ( ) ;
49+ }
50+ }
3551}
Original file line number Diff line number Diff line change 1- <Project Sdk =" Microsoft.NET.Sdk" >
1+ <Project Sdk =" Microsoft.NET.Sdk" >
22
33 <Import Project =" ..\..\build\packages.props" />
44
1616 <PackageReference Include =" AutoMapper" Version =" 8.0.0" />
1717 <PackageReference Include =" MediatR" Version =" 6.0.0" />
1818 <PackageReference Include =" MediatR.Extensions.Microsoft.DependencyInjection" Version =" 6.0.1" />
19+ <PackageReference Include =" Microsoft.Extensions.Configuration" Version =" 2.2.0" />
20+ <PackageReference Include =" Microsoft.Extensions.Configuration.FileExtensions" Version =" 2.2.0" />
1921 <PackageReference Include =" Microsoft.Extensions.Options.ConfigurationExtensions" Version =" 2.2.0" />
2022 <PackageReference Include =" Microsoft.Extensions.Configuration.Abstractions" Version =" 2.2.0" />
2123 <PackageReference Include =" Microsoft.AspNetCore.ResponseCaching" Version =" 2.2.0" />
You can’t perform that action at this time.
0 commit comments