示例#1
0
        internal static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((hostContext, config) =>
        {
            _env = hostContext.HostingEnvironment;
            Log.Information($"=== Running Backend in {_env.EnvironmentName} Environment setting. ===");
            _env.LogConfigurationAndEnvironment();

            _appConfig = config
                         .SetBasePath(_env.ContentRootPath)
                         .AddJsonFile("appsettings.json", optional: false)
                         .AddJsonFile($"appsettings.{_env.EnvironmentName}.json", optional: false)
                         .AddEnvironmentVariables()
                         .AddCommandLine(args).Build();
            Log.Information($"=== Found and loaded 'appsettings.{_env.EnvironmentName}.json'\n");
        })
        .ConfigureMetricsWithDefaults(builder =>
        {
            builder.Report
            .If(!EnvironmentExtension.IsDockerEnvironment(), a =>
                a.ToInfluxDb("http://localhost:8086", "thorsso_metrics", TimeSpan.FromSeconds(5)))
            .If(EnvironmentExtension.IsDockerEnvironment(), a =>
                a.ToInfluxDb("http://influxdb:8086", "thorsso_metrics", TimeSpan.FromSeconds(5)));
        })
        .ConfigureWebHostDefaults(webBuilder =>
        {
            webBuilder.UseStartup <Startup>();
        })
        .UseAutofac()
        .UseSerilog();
示例#2
0
        /// <summary>
        /// Получаем настройки.
        /// </summary>
        /// <returns>Представляет набор свойств конфигурации приложения ключ/значение.</returns>
        private static IConfiguration GetConfiguration()
        {
            IConfigurationBuilder configurationBuilder = new ConfigurationBuilder();

            configurationBuilder
            .AddJsonFile($"appsettings.json", true, true)
            .AddJsonFile($"appsettings.{EnvironmentExtension.GetEnvironmentName()}.json", true, true);

            configurationBuilder.AddEnvironmentVariables();

            return(configurationBuilder.Build());
        }
示例#3
0
        private void ConfigureVirtualFileSystem(ServiceConfigurationContext context)
        {
            var hostingEnvironment = context.Services.GetHostingEnvironment();

            if (hostingEnvironment.IsDevelopment() && !EnvironmentExtension.IsDockerEnvironment())
            {
                Configure <AbpVirtualFileSystemOptions>(options =>
                {
                    options.FileSets.ReplaceEmbeddedByPhysical <SSODomainSharedModule>(
                        Path.Combine(hostingEnvironment.ContentRootPath,
                                     $"..{Path.DirectorySeparatorChar}Thor.SSO.Domain.Shared"));
                    options.FileSets.ReplaceEmbeddedByPhysical <SSODomainModule>(
                        Path.Combine(hostingEnvironment.ContentRootPath,
                                     $"..{Path.DirectorySeparatorChar}Thor.SSO.Domain"));
                    options.FileSets.ReplaceEmbeddedByPhysical <SSOApplicationContractsModule>(
                        Path.Combine(hostingEnvironment.ContentRootPath,
                                     $"..{Path.DirectorySeparatorChar}Thor.SSO.Application.Contracts"));
                    options.FileSets.ReplaceEmbeddedByPhysical <SSOApplicationModule>(
                        Path.Combine(hostingEnvironment.ContentRootPath,
                                     $"..{Path.DirectorySeparatorChar}Thor.SSO.Application"));
                });
            }
        }
示例#4
0
        public static int Main(string[] args)
        {
            Log.Logger = new LoggerConfiguration()
#if DEBUG
                         .MinimumLevel.Debug()
#else
                         .MinimumLevel.Information()
#endif
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
                         .Enrich.FromLogContext()
                         .If(EnvironmentExtension.IsDockerEnvironment(),
                             a => a.WriteTo.GrafanaLoki("http://loki:3100"))
                         .If(!EnvironmentExtension.IsDockerEnvironment(),
                             a => a.WriteTo.GrafanaLoki("http://localhost:3100"))
#if DEBUG
                         .WriteTo.Async(c => c.Console())
#endif
                         .CreateLogger();

            try
            {
                Log.Information("Starting Thor.SSO.HttpApi.Host.");
                CreateHostBuilder(args).Build().Run();
                return(0);
            }
            catch (Exception ex)
            {
                Log.Fatal(ex, "Host terminated unexpectedly!");
                return(1);
            }
            finally
            {
                Log.CloseAndFlush();
            }
        }
 public void Utilities_EnvironmentsExtension_EnvironmentFromName_IfInvalidNameIsProvided_ThrowsException()
 {
     Assert.Throws <ArgumentException>(() => EnvironmentExtension.EnvironmentFromName("invalid"));
 }
        public void Utilities_EnvironmentsExtension_EnvironmentFromName_IfValidNameIsProvided_ReturnsCorrectEnvironment(string name, Environments expectedResult)
        {
            var environment = EnvironmentExtension.EnvironmentFromName(name);

            Assert.AreEqual(expectedResult, environment);
        }