File tree 3 files changed +28
-4
lines changed
3 files changed +28
-4
lines changed Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using System . IO ;
3
+ using Microsoft . Extensions . Configuration ;
4
+
5
+ namespace Volvox . Helios . Web
6
+ {
7
+ public static class ConfigurationHelper
8
+ {
9
+ public static IConfiguration GetDefaultConfiguration ( )
10
+ {
11
+ var environment = Environment . GetEnvironmentVariable ( "ASPNETCORE_ENVIRONMENT" ) ;
12
+ return new ConfigurationBuilder ( )
13
+ . SetBasePath ( Directory . GetCurrentDirectory ( ) )
14
+ . AddJsonFile ( "./appsettings.json" , optional : false , reloadOnChange : true )
15
+ . AddJsonFile ( $ "./appsettings.{ environment } .json", optional : true , reloadOnChange : true )
16
+ . AddJsonFile ( "./modulemetadata.json" )
17
+ . AddUserSecrets < Startup > ( ) . Build ( ) ;
18
+ }
19
+ }
20
+ }
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args)
17
17
return WebHost . CreateDefaultBuilder ( args )
18
18
. UseApplicationInsights ( )
19
19
. UseStartup < Startup > ( )
20
- . ConfigureAppConfiguration ( c => c . AddJsonFile ( "./modulemetadata.json" ) )
20
+ . UseConfiguration ( ConfigurationHelper . GetDefaultConfiguration ( ) )
21
21
. ConfigureLogging ( ( hostingContext , logging ) =>
22
22
{
23
23
logging . AddConfiguration ( hostingContext . Configuration . GetSection ( "Logging" ) ) ;
Original file line number Diff line number Diff line change 1
1
using Microsoft . EntityFrameworkCore ;
2
2
using Microsoft . EntityFrameworkCore . Design ;
3
+ using Microsoft . Extensions . Configuration ;
4
+ using Volvox . Helios . Service ;
3
5
4
- namespace Volvox . Helios . Service
6
+ namespace Volvox . Helios . Web
5
7
{
6
8
public class VolvoxHeliosContextFactory : IDesignTimeDbContextFactory < VolvoxHeliosContext >
7
9
{
8
10
public VolvoxHeliosContext CreateDbContext ( string [ ] args )
9
11
{
12
+ var configuration = ConfigurationHelper . GetDefaultConfiguration ( ) ;
13
+
10
14
var optionsBuilder = new DbContextOptionsBuilder < VolvoxHeliosContext > ( ) ;
11
- optionsBuilder . UseSqlServer (
12
- "Server=(localdb)\\ mssqllocaldb;Database=VolvoxHelios;Trusted_Connection=True;" ) ;
13
15
16
+ optionsBuilder . UseSqlServer ( configuration . GetConnectionString ( "VolvoxHeliosDatabase" ) , options=>
17
+ options . MigrationsAssembly ( "Volvox.Helios.Service" ) ) ;
14
18
return new VolvoxHeliosContext ( optionsBuilder . Options ) ;
15
19
}
16
20
}
You can’t perform that action at this time.
0 commit comments