diff options
author | crupest <crupest@outlook.com> | 2021-01-23 01:16:24 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2021-01-23 01:17:02 +0800 |
commit | 0691b654e114274b73e5a0aa1c1b0842445e57ef (patch) | |
tree | a8f7688dec938e041f151a2db844fc6a50cf9087 /BackEnd/Timeline | |
parent | fca1b6bf2ef01990915a892c2ad4dc27aca4f211 (diff) | |
download | timeline-0691b654e114274b73e5a0aa1c1b0842445e57ef.tar.gz timeline-0691b654e114274b73e5a0aa1c1b0842445e57ef.tar.bz2 timeline-0691b654e114274b73e5a0aa1c1b0842445e57ef.zip |
feat: Now configuration uses environment variables starts with 'Timeline_'. And remove work dir config in launch profiles.
Diffstat (limited to 'BackEnd/Timeline')
-rw-r--r-- | BackEnd/Timeline/Program.cs | 51 | ||||
-rw-r--r-- | BackEnd/Timeline/Properties/launchSettings.json | 9 |
2 files changed, 31 insertions, 29 deletions
diff --git a/BackEnd/Timeline/Program.cs b/BackEnd/Timeline/Program.cs index 87e330a2..1f0f72b9 100644 --- a/BackEnd/Timeline/Program.cs +++ b/BackEnd/Timeline/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System.Resources;
@@ -10,34 +11,38 @@ using Timeline.Services; namespace Timeline
{
- public static class Program
+ public static class Program
+ {
+ public static void Main(string[] args)
{
- public static void Main(string[] args)
- {
- var host = CreateWebHostBuilder(args).Build();
-
- var env = host.Services.GetRequiredService<IWebHostEnvironment>();
+ var host = CreateWebHostBuilder(args).Build();
- var databaseBackupService = host.Services.GetRequiredService<IDatabaseBackupService>();
- databaseBackupService.BackupNow();
+ var env = host.Services.GetRequiredService<IWebHostEnvironment>();
- if (env.IsProduction())
- {
- using (var scope = host.Services.CreateScope())
- {
- var databaseContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
- databaseContext.Database.Migrate();
- }
- }
+ var databaseBackupService = host.Services.GetRequiredService<IDatabaseBackupService>();
+ databaseBackupService.BackupNow();
- host.Run();
+ if (env.IsProduction())
+ {
+ using (var scope = host.Services.CreateScope())
+ {
+ var databaseContext = scope.ServiceProvider.GetRequiredService<DatabaseContext>();
+ databaseContext.Database.Migrate();
}
+ }
- public static IHostBuilder CreateWebHostBuilder(string[] args) =>
- Host.CreateDefaultBuilder(args)
- .ConfigureWebHostDefaults(webBuilder =>
- {
- webBuilder.UseStartup<Startup>();
- });
+ host.Run();
}
+
+ public static IHostBuilder CreateWebHostBuilder(string[] args) =>
+ Host.CreateDefaultBuilder(args)
+ .ConfigureAppConfiguration(config =>
+ {
+ config.AddEnvironmentVariables("Timeline_");
+ })
+ .ConfigureWebHostDefaults(webBuilder =>
+ {
+ webBuilder.UseStartup<Startup>();
+ });
+ }
}
diff --git a/BackEnd/Timeline/Properties/launchSettings.json b/BackEnd/Timeline/Properties/launchSettings.json index a31485ed..db58cd31 100644 --- a/BackEnd/Timeline/Properties/launchSettings.json +++ b/BackEnd/Timeline/Properties/launchSettings.json @@ -5,23 +5,20 @@ "applicationUrl": "http://0.0.0.0:5000",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
- "ASPNETCORE_FRONTEND": "Proxy",
- "ASPNETCORE_WORKDIR": "D:\\timeline-development"
+ "ASPNETCORE_FRONTEND": "Proxy"
}
},
"Dev-Mock": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
- "ASPNETCORE_FRONTEND": "Mock",
- "ASPNETCORE_WORKDIR": "D:\\timeline-development"
+ "ASPNETCORE_FRONTEND": "Mock"
}
},
"Staging": {
"commandName": "Project",
"environmentVariables": {
- "ASPNETCORE_ENVIRONMENT": "Staging",
- "ASPNETCORE_WORKDIR": "D:\\timeline-development"
+ "ASPNETCORE_ENVIRONMENT": "Staging"
}
}
}
|