using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Options; namespace zero.Api; public class ZeroApiPlugin : ZeroPlugin { internal Action PostConfigureServices = null; public ZeroApiPlugin() { Options.Name = "zero.Api"; } public override void ConfigureServices(IServiceCollection services, IConfiguration configuration) { services.AddOptions().Bind(configuration.GetSection("Zero:Api")).Configure(ConfigureOptions); services.TryAddEnumerable(ServiceDescriptor.Transient, ZeroApiMvcOptions>()); services.AddTransient(); services.AddTransient(); services.ConfigureOptions(); ZeroModuleCollection modules = new(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.Add(); modules.ConfigureServices(services, configuration); PostConfigureServices?.Invoke(services, configuration); } public override void Configure(IApplicationBuilder app, IEndpointRouteBuilder routes, IServiceProvider serviceProvider) { string path = "/zero/api"; app.UseWhen(ctx => ctx.Request.Path.StartsWithSegments(path), appScoped => { appScoped.UseEndpoints(endpoints => { //IZeroOptions options = app.ApplicationServices.GetService(); // TODO oO // see https://our.umbraco.com/documentation/reference/routing/custom-routes#where-to-put-your-routing-logic //string path = options.BackofficePath.EnsureStartsWith('/').TrimEnd('/'); //endpoints.MapFallbackToController(path + "/{**path}", "Index", "ZeroIndex"); //endpoints.MapControllers(); }); }); } protected void ConfigureOptions(ApiOptions options, IWebHostEnvironment env) { options.Search.Enabled = true; //Map().Display((x, res, opts) => //{ // PageType pageType = opts.Pages.GetByAlias(x.PageTypeAlias); // if (pageType != null) // { // res.Icon = pageType.Icon; // } // res.Url = "/pages/edit/" + x.Id; //}); //Map("fth-image"); } }