IW4M-Admin/WebfrontCore/Program.cs

51 lines
1.8 KiB
C#
Raw Normal View History

using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
2018-02-21 20:29:23 -05:00
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
2023-04-05 10:54:57 -04:00
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using WebfrontCore.Middleware;
2018-02-21 20:29:23 -05:00
namespace WebfrontCore
{
public class Program
{
public static IManager Manager;
2023-04-05 10:54:57 -04:00
private static IWebHost _webHost;
2023-04-05 10:54:57 -04:00
public static IServiceProvider InitializeServices(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
2018-02-21 20:29:23 -05:00
{
2023-04-05 10:54:57 -04:00
_webHost = BuildWebHost(registerDependenciesAction, bindUrl);
Manager = _webHost.Services.GetRequiredService<IManager>();
return _webHost.Services;
2018-04-08 02:44:42 -04:00
}
2018-03-09 03:01:12 -05:00
2023-04-05 10:54:57 -04:00
public static Task GetWebHostTask(CancellationToken cancellationToken)
{
var config = _webHost.Services.GetRequiredService<ApplicationConfiguration>();
Manager.MiddlewareActionHandler.Register(null,
new CustomCssAccentMiddlewareAction("#007ACC", "#fd7e14", config.WebfrontPrimaryColor,
config.WebfrontSecondaryColor), "custom_css_accent");
return _webHost?.RunAsync(cancellationToken);
}
private static IWebHost BuildWebHost(Action<IServiceCollection> registerDependenciesAction, string bindUrl)
{
return new WebHostBuilder()
#if DEBUG
.UseContentRoot(Path.GetFullPath(Path.Combine(Directory.GetCurrentDirectory(), @"..\..\..\..\", "WebfrontCore")))
#else
.UseContentRoot(SharedLibraryCore.Utilities.OperatingDirectory)
#endif
2023-04-05 10:54:57 -04:00
.UseUrls(bindUrl)
2018-04-08 02:44:42 -04:00
.UseKestrel()
2023-04-05 10:54:57 -04:00
.ConfigureServices(registerDependenciesAction)
2018-02-21 20:29:23 -05:00
.UseStartup<Startup>()
.Build();
}
2018-02-21 20:29:23 -05:00
}
}