Added a simple web api abstraction method
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using HopFrame.Core;
|
||||
using HopFrame.Core.Config;
|
||||
using HopFrame.Web.Components;
|
||||
using HopFrame.Web.Components.Pages;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.FluentUI.AspNetCore.Components;
|
||||
@@ -15,11 +16,12 @@ public static class ServiceCollectionExtensions {
|
||||
/// <param name="services">The service collection to add the services to</param>
|
||||
/// <param name="configurator">The configurator used to build the HopFrame configuration</param>
|
||||
/// <param name="fluentUiLibraryConfiguration">The configuration for the FluentUI components</param>
|
||||
/// <param name="addRazorComponents">Set this to false if you don't want to automatically configure razor components with interactive server components</param>
|
||||
/// <returns>The same service collection that is passed in</returns>
|
||||
public static IServiceCollection AddHopFrame(this IServiceCollection services, Action<HopFrameConfigurator> configurator, LibraryConfiguration? fluentUiLibraryConfiguration = null) {
|
||||
public static IServiceCollection AddHopFrame(this IServiceCollection services, Action<HopFrameConfigurator> configurator, LibraryConfiguration? fluentUiLibraryConfiguration = null, bool addRazorComponents = true) {
|
||||
var config = new HopFrameConfig();
|
||||
configurator.Invoke(new HopFrameConfigurator(config));
|
||||
return AddHopFrame(services, config, fluentUiLibraryConfiguration);
|
||||
return AddHopFrame(services, config, fluentUiLibraryConfiguration, addRazorComponents);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -28,22 +30,46 @@ public static class ServiceCollectionExtensions {
|
||||
/// <param name="services">The service collection to add the services to</param>
|
||||
/// <param name="config">The config used for the HopFrame admin ui</param>
|
||||
/// <param name="fluentUiLibraryConfiguration">The configuration for the FluentUI components</param>
|
||||
/// <param name="addRazorComponents">Set this to false if you don't want to automatically configure razor components with interactive server components</param>
|
||||
/// <returns>The same service collection that is passed in</returns>
|
||||
public static IServiceCollection AddHopFrame(this IServiceCollection services, HopFrameConfig config, LibraryConfiguration? fluentUiLibraryConfiguration = null) {
|
||||
public static IServiceCollection AddHopFrame(this IServiceCollection services, HopFrameConfig config, LibraryConfiguration? fluentUiLibraryConfiguration = null, bool addRazorComponents = true) {
|
||||
services.AddSingleton(config);
|
||||
services.AddHopFrameServices();
|
||||
services.AddFluentUIComponents(fluentUiLibraryConfiguration);
|
||||
|
||||
if (addRazorComponents) {
|
||||
services.AddRazorComponents()
|
||||
.AddInteractiveServerComponents();
|
||||
}
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Maps the HopFrame admin ui endpoints
|
||||
/// Adds the HopFrame admin ui endpoints
|
||||
/// </summary>
|
||||
/// <seealso cref="AddHopFramePages"/>
|
||||
[Obsolete($"Use '{nameof(AddHopFramePages)}' instead")]
|
||||
public static RazorComponentsEndpointConventionBuilder MapHopFramePages(this RazorComponentsEndpointConventionBuilder builder) {
|
||||
return AddHopFramePages(builder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds the HopFrame admin ui endpoints
|
||||
/// </summary>
|
||||
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<App>()
|
||||
.AddInteractiveServerRenderMode();
|
||||
return app;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user