From 87f64e2884460e2ea0f5976d3c213cba5ad8e3a1 Mon Sep 17 00:00:00 2001 From: ktutak1337 Date: Wed, 27 Mar 2024 02:55:47 +0100 Subject: [PATCH] Setup(Mapster): Integrate Mapster into the project: - Added Mapster - Refactored infrastructure registration in Program.cs --- .../StellarChat.Server.Api/Extensions.cs | 30 +++++++++++++++++++ src/Server/StellarChat.Server.Api/Program.cs | 6 ++-- .../StellarChat.Server.Api.csproj | 2 ++ 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 src/Server/StellarChat.Server.Api/Extensions.cs diff --git a/src/Server/StellarChat.Server.Api/Extensions.cs b/src/Server/StellarChat.Server.Api/Extensions.cs new file mode 100644 index 0000000..16595cc --- /dev/null +++ b/src/Server/StellarChat.Server.Api/Extensions.cs @@ -0,0 +1,30 @@ +using Mapster; +using MapsterMapper; +using System.Reflection; +using StellarChat.Shared.Infrastructure; + +namespace StellarChat.Server.Api; + +internal static class Extensions +{ + public static void AddInfrastructure(this WebApplicationBuilder builder) + { + builder.AddSharedInfrastructure(); + + builder.Services.AddMappings(); + } + + public static WebApplication UseInfrastructure(this WebApplication app) + => app.UseSharedInfrastructure(); + + public static IServiceCollection AddMappings(this IServiceCollection services) + { + var config = TypeAdapterConfig.GlobalSettings; + config.Scan(Assembly.GetExecutingAssembly()); + + services.AddSingleton(config); + services.AddScoped(); + + return services; + } +} diff --git a/src/Server/StellarChat.Server.Api/Program.cs b/src/Server/StellarChat.Server.Api/Program.cs index 769cd76..24f9b1a 100644 --- a/src/Server/StellarChat.Server.Api/Program.cs +++ b/src/Server/StellarChat.Server.Api/Program.cs @@ -1,11 +1,11 @@ -using StellarChat.Shared.Infrastructure; +using StellarChat.Server.Api; var builder = WebApplication.CreateBuilder(args); -builder.AddSharedInfrastructure(); +builder.AddInfrastructure(); var app = builder.Build(); -app.UseSharedInfrastructure(); +app.UseInfrastructure(); app.Run(); diff --git a/src/Server/StellarChat.Server.Api/StellarChat.Server.Api.csproj b/src/Server/StellarChat.Server.Api/StellarChat.Server.Api.csproj index 919d4e3..256f610 100644 --- a/src/Server/StellarChat.Server.Api/StellarChat.Server.Api.csproj +++ b/src/Server/StellarChat.Server.Api/StellarChat.Server.Api.csproj @@ -9,6 +9,8 @@ + +