Adds initial ASP.NET Core MVC replacement for Blazor WASM

This commit is contained in:
BinaryAlley committed 2024-09-26 19:58:08 +03:00
1 parent 5409200c7a
commit 193861c9c5
56 files changed
+505 -4139

No files matched your search

@@ -3,7 +3,6 @@ using Lumina.Presentation.Web.Common.Exceptions;
using Lumina.Presentation.Web.Common.Models.Common;
using Lumina.Presentation.Web.Common.Models.Configuration;
using Lumina.Presentation.Web.Common.Models.FileManagement;
using Microsoft.AspNetCore.Components.WebAssembly.Http;
using Microsoft.Extensions.Options;
using System;
using System.Collections.Generic;
@@ -79,13 +78,7 @@ public class ApiHttpClient : IApiHttpClient
/// <returns>An <see cref="IAsyncEnumerable{T}"/> object, which allows for asynchronous iteration over the deserialized items.</returns>
public async IAsyncEnumerable<TResponse?> GetAsyncEnumerable<TResponse>(string endpoint, string? token = null, [EnumeratorCancellation] CancellationToken cancellationToken = default)
{
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
// HttpClient is implemented differently in Blazor WASM, because there are no sockets in the browser, so its BrowserHttpHandler is implemented on top of Fetch API,
// which can provide response content in one of two forms: BrowserHttpContent, which is based on arrayBuffer method (this means that it will always read the response stream to its completion,
// before making the content available), and StreamContent that is wrapping WasmHttpReadStream, which is based on readable streams (this one allows for reading response as it comes).
// WasmHttpReadStream can only work when WebAssemblyEnableStreamingResponse is enabled on request, and only on browsers that support it
request.SetBrowserResponseStreamingEnabled(true);
using HttpRequestMessage request = new(HttpMethod.Get, endpoint);
if (!string.IsNullOrEmpty(token))
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token);
// send the request and expect only headers initially - this prevents the client from buffering the entire response
@@ -1,6 +1,5 @@
using Lumina.Presentation.Web.Common.Models.Configuration;
using Lumina.Presentation.Web.Common.Models.Configuration;
using Lumina.Presentation.Web.Common.Utilities;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
@@ -12,30 +11,18 @@ namespace Lumina.Presentation.Web.Common.DependencyInjection;
internal static class PresentationWebLayerConfiguration
{
#region ===================================================================== METHODS ===================================================================================
/// <summary>
/// Extension method for adding the Lumina.Presentation.Web configuration to the <see cref="WebAssemblyHostBuilder"/>.
/// </summary>
/// <param name="builder">The <see cref="WebAssemblyHostBuilder"/> to add the configuration to.</param>
/// <returns>The updated <see cref="WebAssemblyHostBuilder"/>.</returns>
public static WebAssemblyHostBuilder AddConfiguration(this WebAssemblyHostBuilder builder)
{
// add the configuration sources to the configuration builder
builder.Configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
builder.Configuration.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true);
builder.Services.BindConfiguration(builder.Configuration);
return builder;
}
/// <summary>
/// Extension method for registering the configuration options of the Lumina.Presentation.Web project into the Dependency Injection container.
/// </summary>
/// <param name="serviceCollection">The <see cref="IServiceCollection"/> to bind the configuration options to.</param>
/// <param name="configuration">The configuration to be bound.</param>
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
internal static IServiceCollection BindConfiguration(this IServiceCollection serviceCollection, IConfiguration configuration)
internal static IServiceCollection BindConfiguration(this IServiceCollection serviceCollection, IConfigurationManager configuration)
{
// add the configuration sources to the configuration builder
configuration.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
configuration.AddJsonFile("appsettings.Development.json", optional: true, reloadOnChange: true);
serviceCollection.AddOptions<ServerConfigurationModel>()
.Bind(configuration.GetRequiredSection(ServerConfigurationModel.SECTION_NAME))
.ValidateFluently()
@@ -28,6 +28,8 @@ public static class PresentationWebLayerServices
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddPresentationWebLayerServices(this IServiceCollection services)
{
services.AddControllersWithViews();
// scan the current assembly for validators and register them to the DI container
services.AddValidatorsFromAssemblyContaining<Program>(ServiceLifetime.Singleton);