using HopFrame.Core; using HopFrame.Core.Config; using HopFrame.Core.Callbacks; using HopFrame.Web.Components; using HopFrame.Web.Components.Pages; using HopFrame.Web.Plugins; using HopFrame.Web.Plugins.Internal; using HopFrame.Web.Services; using HopFrame.Web.Services.Implementation; using Microsoft.Extensions.DependencyInjection; using Microsoft.FluentUI.AspNetCore.Components; using Microsoft.AspNetCore.Builder; namespace HopFrame.Web; public static class ServiceCollectionExtensions { /// /// Configures the HopFrame using the provided configurator and adds all internal HopFrame services including the default insecure auth handler if not already provided /// /// The service collection to add the services to /// The configurator used to build the HopFrame configuration /// The configuration for the FluentUI components /// Set this to false if you don't want to automatically configure razor components with interactive server components /// The same service collection that is passed in public static IServiceCollection AddHopFrame(this IServiceCollection services, Action configurator, LibraryConfiguration? fluentUiLibraryConfiguration = null, bool addRazorComponents = true) { var config = new HopFrameConfig(); configurator.Invoke(new HopFrameConfigurator(config, services)); return AddHopFrame(services, config, fluentUiLibraryConfiguration, addRazorComponents); } /// /// Configures the HopFrame using the provided configurator and adds all internal HopFrame services including the default insecure auth handler if not already provided /// /// The service collection to add the services to /// The config used for the HopFrame admin ui /// The configuration for the FluentUI components /// Set this to false if you don't want to automatically configure razor components with interactive server components /// The same service collection that is passed in public static IServiceCollection AddHopFrame(this IServiceCollection services, HopFrameConfig config, LibraryConfiguration? fluentUiLibraryConfiguration = null, bool addRazorComponents = true) { services.AddSingleton(config); services.AddHopFrameServices(); services.AddFluentUIComponents(fluentUiLibraryConfiguration); services.AddScoped(); services.AddScoped(); if (addRazorComponents) { services.AddRazorComponents() .AddInteractiveServerComponents(); } return services; } /// /// Adds the HopFrame admin ui endpoints /// /// [Obsolete($"Use '{nameof(AddHopFramePages)}' instead")] public static RazorComponentsEndpointConventionBuilder MapHopFramePages(this RazorComponentsEndpointConventionBuilder builder) { return AddHopFramePages(builder); } /// /// Adds the HopFrame admin ui endpoints /// public static RazorComponentsEndpointConventionBuilder AddHopFramePages(this RazorComponentsEndpointConventionBuilder builder) { builder .AddInteractiveServerRenderMode() .AddAdditionalAssemblies(typeof(HopFrameHome).Assembly); return builder; } public static WebApplication MapHopFrame(this WebApplication app) { app.UseAntiforgery(); app.MapStaticAssets(); app.MapRazorComponents() .AddInteractiveServerRenderMode(); return app; } }