protected override void Initialize() { Container.RegisterType <IBitmexApiProxy, BitmexApiProxy>(); Container.RegisterType <IBitmexApiService, BitmexApiService>(); Container.RegisterType <IBitmexApiSocketService, BitmexApiSocketService>(); Container.RegisterType <IBitmexApiSocketProxy, BitmexApiSocketProxy>(); Container.RegisterType <IExpiresTimeProvider, ExpiresTimeProvider>(new ContainerControlledLifetimeManager()); Container.RegisterType <ISignatureProvider, SignatureProvider>(new ContainerControlledLifetimeManager()); var config = new ConfigurationBuilder() .AddJsonFile("appsettings.test.json") .Build(); var key = config.GetValue <string>("Key"); var secret = config.GetValue <string>("Secret"); var env = config.GetValue <string>("Environment"); var bitmexEnvironment = (BitmexEnvironment)Enum.Parse(typeof(BitmexEnvironment), env); var authorization = new BitmexAuthorization { Key = key, Secret = secret, BitmexEnvironment = bitmexEnvironment, }; Container.RegisterInstance <IBitmexAuthorization>(authorization); }
public static IServiceCollection AddSeriLog(this IServiceCollection services) { var env = new Microsoft.Extensions.Configuration.ConfigurationBuilder() .AddEnvironmentVariables() .Build(); // get variables from environment to pass to config (if exist) string basePath = env.GetValue <string>("appdirectory").NullToEmpty(); var configuration = new ConfigurationBuilder() .AddJsonFile(basePath + "appsettings.json", optional: false) .Build(); Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .ReadFrom.Configuration(configuration) .CreateLogger(); AppDomain.CurrentDomain.DomainUnload += (o, e) => Log.CloseAndFlush(); services.AddLogging(loggingBuilder => { loggingBuilder.AddSerilog(); }); return(services); }
public static IHostBuilder AddAppConfigurationFromEnvironment(this IHostBuilder builder) { var config = new Microsoft.Extensions.Configuration.ConfigurationBuilder() .AddEnvironmentVariables() .Build(); // get variables from environment to pass to config (if exist) string basePath = config.GetValue <string>("appdirectory").NullToEmpty(); return(AddConfiguration(builder, basePath)); }
public override void TestInitialize() { _bitmexAuthorization = Substitute.For <IBitmexAuthorization>(); var container = new UnityContainer(); container.AddNewExtension <BitmexNetUnityExtension>(); container.RegisterInstance <IBitmexAuthorization>(_bitmexAuthorization); Sut = container.Resolve <IBitmexApiSocketService>(); var config = new ConfigurationBuilder() .AddJsonFile("appsettings.test.json") .Build(); var key = config.GetValue <string>("Key"); var secret = config.GetValue <string>("Secret"); var env = config.GetValue <string>("Environment"); _bitmexAuthorization.BitmexEnvironment.Returns(Enum.Parse(typeof(BitmexEnvironment), env)); _bitmexAuthorization.Key.Returns(key); _bitmexAuthorization.Secret.Returns(secret); }
/// <summary> /// Initializes a new instance of the <see cref="Startup"/> class. /// </summary> /// <param name="hostingEnvironment">The environment the application is running under. This can be Development, /// Staging or Production by default.</param> public Startup(IHostingEnvironment hostingEnvironment) { _hostingEnvironment = hostingEnvironment; _configuration = new ConfigurationBuilder() .SetBasePath(_hostingEnvironment.ContentRootPath) // Add configuration from the config.json file. .AddJsonFile("config.json") // Add configuration from an optional config.development.json, config.staging.json or // config.production.json file, depending on the environment. These settings override the ones in the // config.json file. .AddJsonFile($"config.{_hostingEnvironment.EnvironmentName}.json", optional: true) // This reads the configuration keys from the secret store. This allows you to store connection strings // and other sensitive settings, so you don't have to check them into your source control provider. // Only use this in Development, it is not intended for Production use. See // http://go.microsoft.com/fwlink/?LinkID=532709 and // http://docs.asp.net/en/latest/security/app-secrets.html .AddIf( _hostingEnvironment.IsDevelopment(), x => x.AddUserSecrets()) // Add configuration specific to the Development, Staging or Production environments. This config can // be stored on the machine being deployed to or if you are using Azure, in the cloud. These settings // override the ones in all of the above config files. // Note: To set environment variables for debugging navigate to: // Project Properties -> Debug Tab -> Environment Variables // Note: To get environment variables for the machine use the following command in PowerShell: // [System.Environment]::GetEnvironmentVariable("[VARIABLE_NAME]", [System.EnvironmentVariableTarget]::Machine) // Note: To set environment variables for the machine use the following command in PowerShell: // [System.Environment]::SetEnvironmentVariable("[VARIABLE_NAME]", "[VARIABLE_VALUE]", [System.EnvironmentVariableTarget]::Machine) // Note: Environment variables use a colon separator e.g. You can override the site title by creating a // variable named AppSettings:SiteTitle. See http://docs.asp.net/en/latest/security/app-secrets.html .AddEnvironmentVariables() .Build(); if (_hostingEnvironment.IsDevelopment()) { var launchConfiguration = new ConfigurationBuilder() .SetBasePath(_hostingEnvironment.ContentRootPath) .AddJsonFile(@"Properties\launchSettings.json") .Build(); _sslPort = launchConfiguration.GetValue<int>("iisSettings:iisExpress:sslPort"); } }