private IServiceProvider setup(string envName) { var hostBuilder = new XtiHostBuilder(XtiEnvironment.Parse(envName)); hostBuilder.Services.AddSingleton(sp => sp.GetRequiredService <XtiFolder>().AppDataFolder()); var host = hostBuilder.Build(); return(host.Scope()); }
public XtiFolder(XtiEnvironment env) { this.env = env; path = Environment.GetEnvironmentVariable("XTI_Dir") ?? "c:\\xti"; if (string.IsNullOrWhiteSpace(path)) { path = "c:\\xti"; } }
private IServiceProvider setup(string envName = "Test") { Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", envName); var xtiEnv = XtiEnvironment.Parse(envName); var hostBuilder = new XtiHostBuilder(xtiEnv); hostBuilder.Services.AddFileSecretCredentials(xtiEnv); var host = hostBuilder.Build(); return(host.Scope()); }
public XtiHostBuilder(XtiEnvironment xtiEnv, string appName, string appType, string[] args) { Environment.SetEnvironmentVariable("DOTNET_ENVIRONMENT", xtiEnv.EnvironmentName); Configuration = new ConfigurationBuilder(); Configuration.UseXtiConfiguration(xtiEnv, appName, appType, args); Services = new ServiceCollection(); Services.AddSingleton <IHostEnvironment>(new HostingEnvironment { EnvironmentName = xtiEnv.EnvironmentName }); Services.AddSingleton(_ => Configuration.Build()); Services.AddSingleton(sp => (IConfiguration)sp.GetRequiredService <IConfigurationRoot>()); Services.AddSingleton <XtiFolder>(); Services.AddSingleton(_ => xtiEnv); }
public static void AddXtiDataProtection(this IServiceCollection services, XtiEnvironment environment) { const string appName = "XTI_App"; var keyDirPath = new XtiFolder(environment) .SharedAppDataFolder() .WithSubFolder("Keys") .Path(); services .AddDataProtection ( options => options.ApplicationDiscriminator = appName ) .PersistKeysToFileSystem(new DirectoryInfo(keyDirPath)) .SetApplicationName(appName); }
public static void AddFileSecretCredentials(this IServiceCollection services, XtiEnvironment environment) { services.AddXtiDataProtection(environment); services.AddSingleton <ISecretCredentialsFactory>(sp => { var xtiFolder = new XtiFolder(environment); var dataProtector = sp.GetDataProtector(new[] { "XTI_Secrets" }); return(new FileSecretCredentialsFactory(xtiFolder, dataProtector)); }); services.AddSingleton(sp => (SecretCredentialsFactory)sp.GetRequiredService <ISecretCredentialsFactory>()); services.AddSingleton <ISharedSecretCredentialsFactory>(sp => { var xtiFolder = new XtiFolder(environment); var dataProtector = sp.GetDataProtector(new[] { "XTI_Secrets" }); return(new SharedFileSecretCredentialsFactory(xtiFolder, dataProtector)); }); }
internal AppDataFolder WithHostEnvironment(XtiEnvironment env) => WithSubFolder(env.EnvironmentName);
public XtiHostBuilder(XtiEnvironment environment, string appName, string appType) : this(environment, appName, appType, new string[0]) { }
public XtiHostBuilder(XtiEnvironment environment) : this(environment, "", "", new string[0]) { }
public void UseShared() => Environment = XtiEnvironment.Shared;
public void UseStaging() => Environment = XtiEnvironment.Staging;
public void UseTest() => Environment = XtiEnvironment.Test;
public void UseDevelopment() => Environment = XtiEnvironment.Development;
public void UseEnvironment(string envName) => Environment = XtiEnvironment.Parse(envName);
public XtiEnvironmentAccessor(XtiEnvironment environment) { Environment = environment; }
public void UseProduction() => Environment = XtiEnvironment.Production;
public static IConfigurationBuilder UseXtiConfiguration(this IConfigurationBuilder config, XtiEnvironment environment, string appName, string appType, string[] args) { config.Sources.Clear(); var xtiFolder = new XtiFolder(environment); var settingsPaths = xtiFolder.SettingsPaths(appName, appType); foreach (var path in settingsPaths) { config.AddJsonFile ( path, optional: true, reloadOnChange: true ); } config.AddEnvironmentVariables(); if (args != null) { config.AddCommandLine(args); } return(config); }