mirror of https://github.com/abpframework/abp.git
13 changed files with 106 additions and 34 deletions
@ -1,32 +1,27 @@ |
|||
using Microsoft.Extensions.Configuration; |
|||
using System; |
|||
using Microsoft.Extensions.Configuration; |
|||
|
|||
namespace Microsoft.AspNetCore.Hosting |
|||
{ |
|||
public static class AbpHostingEnvironmentExtensions |
|||
{ |
|||
public static IConfigurationRoot BuildConfiguration(this IHostingEnvironment env, AbpAspNetCoreConfigurationOptions options = null) |
|||
public static IConfigurationRoot BuildConfiguration( |
|||
this IHostingEnvironment env, |
|||
ConfigurationBuilderOptions options = null) |
|||
{ |
|||
options = options ?? new AbpAspNetCoreConfigurationOptions(); |
|||
options = options ?? new ConfigurationBuilderOptions(); |
|||
|
|||
var builder = new ConfigurationBuilder() |
|||
.SetBasePath(env.ContentRootPath) |
|||
.AddJsonFile(options.FileName + ".json", optional: true, reloadOnChange: true) |
|||
.AddJsonFile($"{options.FileName}.{env.EnvironmentName}.json", optional: true, reloadOnChange: true) |
|||
.AddEnvironmentVariables(); |
|||
if (options.BasePath.IsNullOrEmpty()) |
|||
{ |
|||
options.BasePath = env.ContentRootPath; |
|||
} |
|||
|
|||
if (env.IsDevelopment()) |
|||
if (options.EnvironmentName.IsNullOrEmpty()) |
|||
{ |
|||
if (options.UserSecretsId != null) |
|||
{ |
|||
builder.AddUserSecrets(options.UserSecretsId); |
|||
} |
|||
else if (options.UserSecretsAssembly != null) |
|||
{ |
|||
builder.AddUserSecrets(options.UserSecretsAssembly, true); |
|||
} |
|||
options.EnvironmentName = env.EnvironmentName; |
|||
} |
|||
|
|||
return builder.Build(); |
|||
return ConfigurationHelper.BuildConfiguration(options); |
|||
} |
|||
} |
|||
} |
|||
|
|||
@ -0,0 +1,43 @@ |
|||
using System; |
|||
using System.IO; |
|||
|
|||
namespace Microsoft.Extensions.Configuration |
|||
{ |
|||
public static class ConfigurationHelper |
|||
{ |
|||
public static IConfigurationRoot BuildConfiguration(ConfigurationBuilderOptions options = null) |
|||
{ |
|||
options = options ?? new ConfigurationBuilderOptions(); |
|||
|
|||
if (options.BasePath.IsNullOrEmpty()) |
|||
{ |
|||
options.BasePath = Directory.GetCurrentDirectory(); |
|||
} |
|||
|
|||
var builder = new ConfigurationBuilder() |
|||
.SetBasePath(options.BasePath) |
|||
.AddJsonFile(options.FileName + ".json", optional: true, reloadOnChange: true); |
|||
|
|||
if (!options.EnvironmentName.IsNullOrEmpty()) |
|||
{ |
|||
builder = builder.AddJsonFile($"{options.FileName}.{options.EnvironmentName}.json", optional: true, reloadOnChange: true); |
|||
} |
|||
|
|||
builder = builder.AddEnvironmentVariables(); |
|||
|
|||
if (options.EnvironmentName == "Development") |
|||
{ |
|||
if (options.UserSecretsId != null) |
|||
{ |
|||
builder.AddUserSecrets(options.UserSecretsId); |
|||
} |
|||
else if (options.UserSecretsAssembly != null) |
|||
{ |
|||
builder.AddUserSecrets(options.UserSecretsAssembly, true); |
|||
} |
|||
} |
|||
|
|||
return builder.Build(); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue