Skip to content

Commit

Permalink
Setup(Mapster): Integrate Mapster into the project:
Browse files Browse the repository at this point in the history
- Added Mapster
- Refactored infrastructure registration in Program.cs
  • Loading branch information
ktutak1337 committed Mar 27, 2024
1 parent 1251b70 commit 87f64e2
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
30 changes: 30 additions & 0 deletions src/Server/StellarChat.Server.Api/Extensions.cs
Original file line number Diff line number Diff line change
@@ -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<IMapper, ServiceMapper>();

return services;
}
}
6 changes: 3 additions & 3 deletions src/Server/StellarChat.Server.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Mapster" Version="7.4.1-pre01" />
<PackageReference Include="Mapster.DependencyInjection" Version="1.0.2-pre01" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.0" />
</ItemGroup>

Expand Down

0 comments on commit 87f64e2

Please sign in to comment.