DocSpace-client/products/ASC.CRM/Server/Program.cs

60 lines
2.1 KiB
C#
Raw Normal View History

2020-03-02 15:38:31 +00:00
using System.Collections.Generic;
2020-04-16 19:41:37 +00:00
using System.IO;
2021-03-02 16:29:07 +00:00
2021-03-13 12:22:14 +00:00
using ASC.Common.DependencyInjection;
using Autofac;
2021-03-02 16:29:07 +00:00
using Autofac.Extensions.DependencyInjection;
2020-03-02 15:38:31 +00:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
namespace ASC.CRM
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
2021-03-02 16:29:07 +00:00
public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
2020-03-02 15:38:31 +00:00
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>();
2020-04-16 19:41:37 +00:00
})
2021-03-02 16:29:07 +00:00
.ConfigureAppConfiguration((hostingContext, config) =>
2020-04-16 19:41:37 +00:00
{
2021-03-02 16:29:07 +00:00
var buided = config.Build();
var path = buided["pathToConf"];
if (!Path.IsPathRooted(path))
2020-04-16 19:41:37 +00:00
{
2021-03-02 16:29:07 +00:00
path = Path.GetFullPath(Path.Combine(hostingContext.HostingEnvironment.ContentRootPath, path));
}
config.SetBasePath(path);
config
2020-04-16 19:41:37 +00:00
.AddJsonFile("appsettings.json")
.AddJsonFile($"appsettings.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
.AddJsonFile("storage.json")
.AddJsonFile("kafka.json")
.AddJsonFile($"kafka.{hostingContext.HostingEnvironment.EnvironmentName}.json", true)
2021-03-02 16:29:07 +00:00
.AddEnvironmentVariables()
.AddCommandLine(args)
.AddInMemoryCollection(new Dictionary<string, string>
{
{"pathToConf", path}
});
2021-03-13 12:22:14 +00:00
})
.ConfigureContainer<ContainerBuilder>((context, builder) =>
{
builder.Register(context.Configuration, context.HostingEnvironment.ContentRootPath, false, false);
2021-03-02 16:29:07 +00:00
});
}
2020-03-02 15:38:31 +00:00
}
}