added builders extensions
This commit is contained in:
parent
8ee71f5574
commit
5e2f575483
53
common/ASC.Api.Core/Extensions/HostBuilderExtension.cs
Normal file
53
common/ASC.Api.Core/Extensions/HostBuilderExtension.cs
Normal file
@ -0,0 +1,53 @@
|
||||
namespace ASC.Api.Core.Extensions;
|
||||
|
||||
public static class HostBuilderExtension
|
||||
{
|
||||
public static IHostBuilder ConfigureBaseAppConfiguration(this IHostBuilder hostBuilder, string[] args, Action<HostBuilderContext, IConfigurationBuilder, IHostEnvironment, string> configureDelegate = null)
|
||||
{
|
||||
hostBuilder.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var buildedConfig = config.Build();
|
||||
|
||||
var path = buildedConfig["pathToConf"];
|
||||
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
|
||||
var env = hostContext.HostingEnvironment;
|
||||
|
||||
config.SetBasePath(path);
|
||||
|
||||
config.AddJsonFile("appsettings.json");
|
||||
|
||||
configureDelegate?.Invoke(hostContext, config, env, path);
|
||||
|
||||
config.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
});
|
||||
});
|
||||
|
||||
return hostBuilder;
|
||||
}
|
||||
|
||||
public static IHostBuilder ConfigureDefaultAppConfiguration(this IHostBuilder hostBuilder, string[] args, Action<HostBuilderContext, IConfigurationBuilder, IHostEnvironment, string> configureDelegate = null)
|
||||
{
|
||||
hostBuilder.ConfigureBaseAppConfiguration(args, (hostContext, config, env, path) =>
|
||||
{
|
||||
config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{env.EnvironmentName}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{env.EnvironmentName}.json", true);
|
||||
|
||||
configureDelegate?.Invoke(hostContext, config, env, path);
|
||||
});
|
||||
|
||||
return hostBuilder;
|
||||
}
|
||||
}
|
33
common/ASC.Api.Core/Extensions/WebHostExtensions.cs
Normal file
33
common/ASC.Api.Core/Extensions/WebHostExtensions.cs
Normal file
@ -0,0 +1,33 @@
|
||||
namespace ASC.Api.Core.Extensions;
|
||||
|
||||
public static class WebHostExtensions
|
||||
{
|
||||
public static IWebHostBuilder ConfigureDefaultKestrel(this IWebHostBuilder webHostBuilder, Action<WebHostBuilderContext, KestrelServerOptions> configureDelegate = null)
|
||||
{
|
||||
webHostBuilder.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
{
|
||||
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
||||
|
||||
if (!kestrelConfig.Exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(unixSocket))
|
||||
{
|
||||
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
||||
|
||||
serverOptions.ListenUnixSocket(unixSocket);
|
||||
}
|
||||
}
|
||||
|
||||
configureDelegate?.Invoke(hostingContext, serverOptions);
|
||||
});
|
||||
|
||||
return webHostBuilder;
|
||||
}
|
||||
}
|
@ -4,7 +4,8 @@ global using System.Globalization;
|
||||
global using System.Linq.Expressions;
|
||||
global using System.Net;
|
||||
|
||||
global using System.Reflection;
|
||||
global using System.Reflection;
|
||||
global using System.Runtime.InteropServices;
|
||||
global using System.Runtime.Serialization;
|
||||
global using System.Security;
|
||||
global using System.Security.Authentication;
|
||||
@ -53,7 +54,8 @@ global using Microsoft.AspNetCore.Builder;
|
||||
global using Microsoft.AspNetCore.Diagnostics.HealthChecks;
|
||||
global using Microsoft.AspNetCore.Hosting;
|
||||
global using Microsoft.AspNetCore.Http;
|
||||
global using Microsoft.AspNetCore.HttpOverrides;
|
||||
global using Microsoft.AspNetCore.HttpOverrides;
|
||||
global using Microsoft.AspNetCore.Server.Kestrel.Core;
|
||||
global using Microsoft.AspNetCore.Mvc;
|
||||
global using Microsoft.AspNetCore.Mvc.ApplicationModels;
|
||||
global using Microsoft.AspNetCore.Mvc.Authorization;
|
||||
|
@ -1,12 +1,12 @@
|
||||
global using System.Linq.Expressions;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.ClearEvents.Services;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
global using ASC.Common.DependencyInjection;
|
||||
global using ASC.Common.Logging;
|
||||
global using ASC.Common.Utils;
|
||||
global using ASC.Core.Common.EF;
|
||||
global using ASC.Core.Tenants;
|
||||
global using ASC.MessagingSystem.Data;
|
||||
|
@ -35,44 +35,29 @@ builder.Host.UseSystemd();
|
||||
builder.Host.UseWindowsService();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var configRoot = config.Build();
|
||||
var path = configRoot["pathToConf"];
|
||||
|
||||
if (!Path.IsPathRooted(path))
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
|
||||
config.SetBasePath(path);
|
||||
|
||||
|
||||
config.AddJsonFile("appsettings.json")
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string> { { "pathToConf", path } });
|
||||
});
|
||||
builder.Host.ConfigureBaseAppConfiguration(args);
|
||||
|
||||
builder.Host.ConfigureServices((hostContext, services) =>
|
||||
{
|
||||
services.AddMemoryCache();
|
||||
|
||||
var diHelper = new DIHelper(services);
|
||||
|
||||
var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
|
||||
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();
|
||||
|
||||
if (kafkaConfiguration != null)
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCacheNotify<>));
|
||||
}
|
||||
else if (redisConfiguration != null)
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCacheNotify<>));
|
||||
}
|
||||
else
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
|
||||
}
|
||||
services.AddMemoryCache();
|
||||
|
||||
var diHelper = new DIHelper(services);
|
||||
|
||||
var redisConfiguration = hostContext.Configuration.GetSection("Redis").Get<RedisConfiguration>();
|
||||
var kafkaConfiguration = hostContext.Configuration.GetSection("kafka").Get<KafkaSettings>();
|
||||
|
||||
if (kafkaConfiguration != null)
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(KafkaCacheNotify<>));
|
||||
}
|
||||
else if (redisConfiguration != null)
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(RedisCacheNotify<>));
|
||||
}
|
||||
else
|
||||
{
|
||||
diHelper.TryAdd(typeof(ICacheNotify<>), typeof(MemoryCacheNotify<>));
|
||||
}
|
||||
|
||||
services.AddHostedService<ClearEventsService>();
|
||||
diHelper.TryAdd<ClearEventsService>();
|
||||
@ -80,7 +65,9 @@ builder.Host.ConfigureServices((hostContext, services) =>
|
||||
});
|
||||
|
||||
builder.Host.ConfigureContainer<ContainerBuilder>((context, builder) =>
|
||||
builder.Register(context.Configuration, false, false));
|
||||
{
|
||||
builder.Register(context.Configuration, false, false);
|
||||
});
|
||||
|
||||
builder.Host.ConfigureNLogLogging();
|
||||
|
||||
|
@ -1,6 +1,7 @@
|
||||
global using System.Runtime.InteropServices;
|
||||
|
||||
global using ASC.Api.Collections;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
@ -23,6 +24,7 @@ global using Autofac;
|
||||
global using Autofac.Extensions.DependencyInjection;
|
||||
|
||||
global using Microsoft.AspNetCore.Mvc;
|
||||
global using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
global using Microsoft.Extensions.Options;
|
||||
|
||||
global using static ASC.Data.Backup.BackupAjaxHandler;
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Microsoft.Extensions.Hosting.WindowsServices;
|
||||
|
||||
var options = new WebApplicationOptions
|
||||
var options = new WebApplicationOptions
|
||||
{
|
||||
Args = args,
|
||||
ContentRootPath = WindowsServiceHelpers.IsWindowsService() ? AppContext.BaseDirectory : default
|
||||
@ -12,57 +10,13 @@ builder.Host.UseWindowsService();
|
||||
builder.Host.UseSystemd();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
builder.WebHost.ConfigureDefaultKestrel();
|
||||
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args, (hostContext, config, env, path) =>
|
||||
{
|
||||
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
||||
|
||||
if (!kestrelConfig.Exists()) return;
|
||||
|
||||
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(unixSocket))
|
||||
{
|
||||
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
||||
|
||||
serverOptions.ListenUnixSocket(unixSocket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var buided = config.Build();
|
||||
|
||||
var path = buided["pathToConf"];
|
||||
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
|
||||
config.SetBasePath(path);
|
||||
|
||||
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
||||
config
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{env}.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env}.json", true)
|
||||
.AddJsonFile("backup.json")
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{env}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{env}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
}
|
||||
);
|
||||
config.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env.EnvironmentName}.json", true)
|
||||
.AddJsonFile("backup.json");
|
||||
});
|
||||
|
||||
builder.Host.ConfigureNLogLogging();
|
||||
|
@ -1,7 +1,8 @@
|
||||
global using System.Data;
|
||||
global using System.Reflection;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
global using ASC.Common.DependencyInjection;
|
||||
|
@ -10,35 +10,12 @@ var startup = new BaseWorkerStartup(builder.Configuration);
|
||||
builder.Host.UseSystemd();
|
||||
builder.Host.UseWindowsService();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args, (hostContext, config, env, path) =>
|
||||
{
|
||||
var buildedConfig = config.Build();
|
||||
var path = buildedConfig["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
|
||||
config.SetBasePath(path);
|
||||
|
||||
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
||||
|
||||
config.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{env}.json", true)
|
||||
.AddJsonFile($"appsettings.services.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env}.json", true)
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{env}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{env}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
});
|
||||
config.AddJsonFile($"appsettings.services.json", true)
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env.EnvironmentName}.json", true);
|
||||
});
|
||||
|
||||
startup.ConfigureServices(builder.Services);
|
||||
|
@ -1,7 +1,7 @@
|
||||
global using System.Reflection;
|
||||
global using System.Runtime.InteropServices;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
global using ASC.Common.Mapping;
|
||||
|
@ -10,53 +10,13 @@ builder.Host.UseWindowsService();
|
||||
builder.Host.UseSystemd();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
builder.WebHost.ConfigureDefaultKestrel();
|
||||
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args, (hostContext, config, env, path) =>
|
||||
{
|
||||
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
||||
|
||||
if (!kestrelConfig.Exists()) return;
|
||||
|
||||
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(unixSocket))
|
||||
{
|
||||
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
||||
|
||||
serverOptions.ListenUnixSocket(unixSocket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var buided = config.Build();
|
||||
var path = buided["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
config.SetBasePath(path);
|
||||
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
||||
config
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{env}.json", true)
|
||||
.AddJsonFile($"appsettings.services.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env}.json", true)
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{env}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{env}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
}
|
||||
);
|
||||
config.AddJsonFile($"appsettings.services.json", true)
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env.EnvironmentName}.json", true);
|
||||
});
|
||||
|
||||
builder.Host.ConfigureServices((hostContext, services) =>
|
||||
|
@ -4,11 +4,11 @@ global using System.Runtime.Caching;
|
||||
global using System.Runtime.InteropServices;
|
||||
global using System.Text.RegularExpressions;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
global using ASC.Common.Logging;
|
||||
global using ASC.Common.Utils;
|
||||
global using ASC.Core;
|
||||
global using ASC.Core.Common.Configuration;
|
||||
global using ASC.Core.Common.Notify;
|
||||
|
@ -10,51 +10,12 @@ builder.Host.UseWindowsService();
|
||||
builder.Host.UseSystemd();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
builder.WebHost.ConfigureDefaultKestrel();
|
||||
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args, (hostContext, config, env, path) =>
|
||||
{
|
||||
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
||||
|
||||
if (!kestrelConfig.Exists()) return;
|
||||
|
||||
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(unixSocket))
|
||||
{
|
||||
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
||||
|
||||
serverOptions.ListenUnixSocket(unixSocket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var buided = config.Build();
|
||||
var path = buided["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
config.SetBasePath(path);
|
||||
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
||||
config
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
}
|
||||
)
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{env}.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env}.json", true)
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{env}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{env}.json", true)
|
||||
.AddEnvironmentVariables();
|
||||
config.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env.EnvironmentName}.json", true);
|
||||
});
|
||||
|
||||
builder.Host.ConfigureNLogLogging();
|
||||
@ -72,4 +33,4 @@ var app = builder.Build();
|
||||
|
||||
startup.Configure(app, app.Environment);
|
||||
|
||||
app.Run();
|
||||
app.Run();
|
@ -4,7 +4,8 @@ global using System.Security.Cryptography;
|
||||
global using System.Text;
|
||||
global using System.Text.Json;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
global using ASC.Common.DependencyInjection;
|
||||
|
@ -10,56 +10,16 @@ builder.Host.UseWindowsService();
|
||||
builder.Host.UseSystemd();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
{
|
||||
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
||||
|
||||
if (!kestrelConfig.Exists()) return;
|
||||
|
||||
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(unixSocket))
|
||||
{
|
||||
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
||||
|
||||
serverOptions.ListenUnixSocket(unixSocket);
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.WebHost.ConfigureDefaultKestrel();
|
||||
|
||||
builder.Host.ConfigureContainer<ContainerBuilder>((context, builder) =>
|
||||
{
|
||||
builder.Register(context.Configuration, false, false);
|
||||
});
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args, (hostContext, config, env, path) =>
|
||||
{
|
||||
var buided = config.Build();
|
||||
var path = buided["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
config.SetBasePath(path);
|
||||
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
||||
config
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
}
|
||||
)
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{env}.json", true)
|
||||
.AddJsonFile($"appsettings.services.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{env}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{env}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args);
|
||||
config.AddJsonFile($"appsettings.services.json", true);
|
||||
});
|
||||
|
||||
builder.WebHost.ConfigureServices((hostContext, services) =>
|
||||
|
@ -8,14 +8,13 @@ global using System.Web;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Convention;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Api.Utils;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Logging;
|
||||
global using ASC.Common.Utils;
|
||||
global using ASC.Common.Web;
|
||||
global using ASC.Core;
|
||||
global using ASC.Core.Billing;
|
||||
global using ASC.Core.Common.Configuration;
|
||||
global using ASC.Core.Common.Settings;
|
||||
global using ASC.Core.Users;
|
||||
global using ASC.FederatedLogin.Helpers;
|
||||
|
@ -10,57 +10,14 @@ builder.Host.UseSystemd();
|
||||
builder.Host.UseWindowsService();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
var buildedConfig = config.Build();
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args);
|
||||
|
||||
var path = buildedConfig["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostingContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
|
||||
config.SetBasePath(path);
|
||||
|
||||
config.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path}
|
||||
});
|
||||
});
|
||||
|
||||
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
builder.WebHost.ConfigureDefaultKestrel((hostingContext, serverOptions) =>
|
||||
{
|
||||
serverOptions.Limits.MaxRequestBodySize = 100 * 1024 * 1024;
|
||||
serverOptions.Limits.MaxRequestBufferSize = 100 * 1024 * 1024;
|
||||
serverOptions.Limits.MinRequestBodyDataRate = null;
|
||||
serverOptions.Limits.MinResponseDataRate = null;
|
||||
|
||||
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
||||
if (!kestrelConfig.Exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(unixSocket))
|
||||
{
|
||||
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
||||
|
||||
serverOptions.ListenUnixSocket(unixSocket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.Host.ConfigureNLogLogging();
|
||||
|
@ -2,7 +2,8 @@
|
||||
global using System.Linq.Expressions;
|
||||
global using System.Reflection;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Common;
|
||||
global using ASC.Common.Caching;
|
||||
global using ASC.Common.DependencyInjection;
|
||||
|
@ -10,37 +10,12 @@ builder.Host.UseSystemd();
|
||||
builder.Host.UseWindowsService();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args, (hostContext, config, env, path) =>
|
||||
{
|
||||
var buildedConfig = config.Build();
|
||||
|
||||
var path = buildedConfig["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
|
||||
config.SetBasePath(path);
|
||||
|
||||
var env = hostContext.Configuration.GetValue("ENVIRONMENT", "Production");
|
||||
|
||||
config.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{env}.json", true)
|
||||
.AddJsonFile($"appsettings.services.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env}.json", true)
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{env}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{env}.json", true)
|
||||
.AddJsonFile("elastic.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
});
|
||||
config.AddJsonFile($"appsettings.services.json", true)
|
||||
.AddJsonFile("notify.json")
|
||||
.AddJsonFile($"notify.{env.EnvironmentName}.json", true)
|
||||
.AddJsonFile("elastic.json", true);
|
||||
});
|
||||
|
||||
builder.Host.ConfigureServices((hostContext, services) =>
|
||||
|
@ -5,6 +5,7 @@ global using System.ServiceModel.Security;
|
||||
global using System.Web;
|
||||
|
||||
global using ASC.Api.Core;
|
||||
global using ASC.Api.Core.Extensions;
|
||||
global using ASC.Api.Core.Convention;
|
||||
global using ASC.Api.Utils;
|
||||
global using ASC.Common;
|
||||
|
@ -11,52 +11,9 @@ builder.Host.UseSystemd();
|
||||
builder.Host.UseWindowsService();
|
||||
builder.Host.UseServiceProviderFactory(new AutofacServiceProviderFactory());
|
||||
|
||||
builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
{
|
||||
var kestrelConfig = hostingContext.Configuration.GetSection("Kestrel");
|
||||
builder.WebHost.ConfigureDefaultKestrel();
|
||||
|
||||
if (!kestrelConfig.Exists())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var unixSocket = kestrelConfig.GetValue<string>("ListenUnixSocket");
|
||||
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(unixSocket))
|
||||
{
|
||||
unixSocket = string.Format(unixSocket, hostingContext.HostingEnvironment.ApplicationName.Replace("ASC.", "").Replace(".", ""));
|
||||
|
||||
serverOptions.ListenUnixSocket(unixSocket);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostingContext, config) =>
|
||||
{
|
||||
var buided = config.Build();
|
||||
var path = buided["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostingContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
|
||||
config.SetBasePath(path);
|
||||
config.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
});
|
||||
});
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args);
|
||||
|
||||
startup.ConfigureServices(builder.Services);
|
||||
|
||||
|
@ -1,3 +1,5 @@
|
||||
using ASC.Api.Core.Extensions;
|
||||
|
||||
var options = new WebApplicationOptions
|
||||
{
|
||||
Args = args,
|
||||
@ -29,32 +31,34 @@ builder.WebHost.ConfigureKestrel((hostingContext, serverOptions) =>
|
||||
}
|
||||
});
|
||||
|
||||
builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
{
|
||||
var buided = config.Build();
|
||||
var path = buided["pathToConf"];
|
||||
if (!Path.IsPathRooted(path))
|
||||
{
|
||||
path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
}
|
||||
config.SetBasePath(path);
|
||||
config
|
||||
.AddJsonFile("appsettings.json")
|
||||
.AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddJsonFile("storage.json")
|
||||
.AddJsonFile("kafka.json")
|
||||
.AddJsonFile($"kafka.{hostContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddJsonFile("redis.json")
|
||||
.AddJsonFile($"redis.{hostContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
.AddEnvironmentVariables()
|
||||
.AddCommandLine(args)
|
||||
.AddInMemoryCollection(new Dictionary<string, string>
|
||||
{
|
||||
{"pathToConf", path }
|
||||
}
|
||||
);
|
||||
builder.Host.ConfigureDefaultAppConfiguration(args);
|
||||
|
||||
});
|
||||
//builder.Host.ConfigureAppConfiguration((hostContext, config) =>
|
||||
//{
|
||||
// var buided = config.Build();
|
||||
// var path = buided["pathToConf"];
|
||||
// if (!Path.IsPathRooted(path))
|
||||
// {
|
||||
// path = Path.GetFullPath(CrossPlatform.PathCombine(hostContext.HostingEnvironment.ContentRootPath, path));
|
||||
// }
|
||||
// config.SetBasePath(path);
|
||||
// config
|
||||
// .AddJsonFile("appsettings.json")
|
||||
// .AddJsonFile($"appsettings.{hostContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
// .AddJsonFile("storage.json")
|
||||
// .AddJsonFile("kafka.json")
|
||||
// .AddJsonFile($"kafka.{hostContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
// .AddJsonFile("redis.json")
|
||||
// .AddJsonFile($"redis.{hostContext.HostingEnvironment.EnvironmentName}.json", true)
|
||||
// .AddEnvironmentVariables()
|
||||
// .AddCommandLine(args)
|
||||
// .AddInMemoryCollection(new Dictionary<string, string>
|
||||
// {
|
||||
// {"pathToConf", path }
|
||||
// }
|
||||
// );
|
||||
|
||||
//});
|
||||
|
||||
builder.Host.ConfigureNLogLogging();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user