2021-11-29 18:25:50 +01:00
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2021-12-01 13:03:06 +01:00
|
|
|
using Microsoft.AspNetCore.Mvc;
|
2021-11-22 16:03:02 +01:00
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2021-12-03 14:45:49 +01:00
|
|
|
using Microsoft.Extensions.DependencyInjection.Extensions;
|
|
|
|
|
using Microsoft.Extensions.Options;
|
2021-11-23 22:56:22 +01:00
|
|
|
using System.IO;
|
2021-12-03 14:45:49 +01:00
|
|
|
using zero.Backoffice.Endpoints.Account;
|
2021-12-20 13:03:56 +01:00
|
|
|
using zero.Backoffice.Endpoints.Pages;
|
2021-12-03 15:49:34 +01:00
|
|
|
using zero.Backoffice.Services;
|
2021-11-22 16:03:02 +01:00
|
|
|
|
|
|
|
|
namespace zero.Backoffice;
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
public class ZeroBackofficePlugin : ZeroPlugin
|
2021-11-22 16:03:02 +01:00
|
|
|
{
|
2021-11-23 22:56:22 +01:00
|
|
|
internal Action<IServiceCollection, IConfiguration> PostConfigureServices = null;
|
|
|
|
|
|
|
|
|
|
|
2021-11-22 16:03:02 +01:00
|
|
|
public ZeroBackofficePlugin()
|
|
|
|
|
{
|
2021-11-23 22:56:22 +01:00
|
|
|
Options.Name = "zero.Backoffice";
|
2021-11-22 16:03:02 +01:00
|
|
|
Options.LocalizationPaths.Add("~/Resources/Localization/zero.{lang}.json");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public override void ConfigureServices(IServiceCollection services, IConfiguration configuration)
|
|
|
|
|
{
|
2021-11-23 22:56:22 +01:00
|
|
|
services.AddOptions<BackofficeOptions>().Bind(configuration.GetSection("Zero:Backoffice")).Configure<IWebHostEnvironment>(ConfigureOptions);
|
2021-12-03 14:45:49 +01:00
|
|
|
services.TryAddEnumerable(ServiceDescriptor.Transient<IConfigureOptions<MvcOptions>, ZeroBackofficeMvcOptions>());
|
2021-11-23 22:56:22 +01:00
|
|
|
services.AddHostedService<ZeroDevService>();
|
|
|
|
|
services.AddTransient<IZeroVue, ZeroVue>();
|
2021-12-03 14:45:49 +01:00
|
|
|
services.AddSingleton<IMapperProfile, AccountMapperProfile>();
|
2021-12-20 13:03:56 +01:00
|
|
|
services.AddScoped<IPageTreeService, PageTreeService>();
|
2021-11-22 16:03:02 +01:00
|
|
|
|
2021-12-06 13:29:15 +01:00
|
|
|
services.AddSingleton<IIconService, IconService>();
|
|
|
|
|
services.AddSingleton<IResourceService, ResourceService>();
|
2021-12-23 09:07:34 +01:00
|
|
|
services.AddScoped<ISectionService, SectionService>();
|
2021-12-03 15:49:34 +01:00
|
|
|
|
|
|
|
|
services.AddSingleton<IBackofficeAssetFileSystem, BackofficeAssetFileSystem>(svc =>
|
|
|
|
|
{
|
|
|
|
|
IOptions<BackofficeOptions> options = svc.GetRequiredService<IOptions<BackofficeOptions>>();
|
|
|
|
|
IWebHostEnvironment env = svc.GetRequiredService<IWebHostEnvironment>();
|
|
|
|
|
return new(Path.Combine(env.WebRootPath, options.Value.AssetPath));
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-24 14:37:32 +01:00
|
|
|
services.AddZeroBackofficeUIComposition();
|
|
|
|
|
|
|
|
|
|
//services.AddTransient<ISectionsApi, SectionsApi>();
|
|
|
|
|
//services.AddTransient<ISettingsApi, SettingsApi>();
|
|
|
|
|
|
|
|
|
|
//services.AddScoped<IBackofficeSearchService, BackofficeSearchService>();
|
2021-11-23 22:56:22 +01:00
|
|
|
|
2021-11-29 00:38:55 +01:00
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
PostConfigureServices?.Invoke(services, configuration);
|
2021-11-22 16:03:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
protected void ConfigureOptions(BackofficeOptions options, IWebHostEnvironment env)
|
2021-11-22 16:03:02 +01:00
|
|
|
{
|
2021-12-03 15:49:34 +01:00
|
|
|
options.ExcludedPaths.Add("resources");
|
|
|
|
|
options.AssetPath = "zero/resources";
|
|
|
|
|
|
2021-11-23 22:56:22 +01:00
|
|
|
options.DevServer.WorkingDirectory = Path.Combine(env.ContentRootPath, "..", "Zero.Web.UI", "App");
|
|
|
|
|
|
2021-11-22 16:03:02 +01:00
|
|
|
options.IconSets.Add(new BackofficeIconSet()
|
|
|
|
|
{
|
|
|
|
|
Alias = "feather",
|
|
|
|
|
Name = "Feather",
|
2021-12-03 15:49:34 +01:00
|
|
|
SpritePath = "icons/feather.svg",
|
2021-11-22 16:03:02 +01:00
|
|
|
Prefix = "fth"
|
|
|
|
|
});
|
|
|
|
|
|
2021-11-24 15:49:25 +01:00
|
|
|
options.SupportedLanguages = new string[2] { "en-US", "de-DE" };
|
|
|
|
|
options.DefaultLanguage = options.SupportedLanguages[0];
|
2021-11-22 16:03:02 +01:00
|
|
|
}
|
|
|
|
|
}
|