< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 59
Coverable lines: 59
Total lines: 93
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 4
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
<Main>$(...)0%2040%

File(s)

/home/runner/work/ClientManagerDemo/ClientManagerDemo/src/ClientManager/ClientManager.API/Program.cs

#LineLine coverage
 1using ClientManager.API.Services;
 2using ClientManager.Shared.Configuration;
 3using ClientManager.Shared.Data;
 4using ClientManager.Shared.Messaging;
 5using Microsoft.EntityFrameworkCore;
 6using Microsoft.Extensions.Options;
 7using Serilog;
 8
 09var builder = WebApplication.CreateBuilder(args);
 10
 11// Logging
 012builder.Host.UseSerilog((context, loggerConfig) => loggerConfig.ReadFrom.Configuration(context.Configuration).Enrich.Fro
 13
 14// Load .env file if it exists
 015ConfigurationHelper.LoadDotEnvFile();
 016builder.Configuration.AddEnvironmentVariables();
 17
 18// Map configuration sections to strongly typed classes
 019builder.Services.Configure<PostgresConnectionConfiguration>(builder.Configuration.GetSection("POSTGRES"));
 020builder.Services.Configure<RabbitMQConnectionConfiguration>(builder.Configuration.GetSection("RABBITMQ"));
 21
 22// Add services to the container.
 23// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
 024builder.Services.AddEndpointsApiExplorer();
 025builder.Services.AddSwaggerGen();
 026builder.Services.AddControllers();
 027builder.Services.AddSignalR();
 028builder.Services.AddCors();
 029builder.Services.AddHealthChecks();
 030builder.Services.AddHostedService<EventForwarder>();
 031builder.Services.AddScoped<IClientService, ClientService>();
 32
 33// Context accessor using AsyncLocal to store per-message context
 034builder.Services.AddSingleton<IMessageContextAccessor, MessageContextAccessor>();
 35
 36// Core publishing components
 037builder.Services.AddSingleton<IMessagePublisher, MessagePublisher>();
 038builder.Services.AddSingleton<IRoutingConvention, RoutingConvention>();
 39
 40// Message Publishing middleware
 041builder.Services.AddSingleton<IMessagePublishMiddleware, MessageValidationMiddleware>();
 042builder.Services.AddSingleton<IMessagePublishMiddleware, ContextEnrichmentMiddleware>();
 043builder.Services.AddSingleton<MessagePublishPipeline>(sp =>
 044{
 045    var middlewares = sp.GetServices<IMessagePublishMiddleware>();
 046    var pipeline = new MessagePublishPipeline();
 047
 048    foreach (var middleware in middlewares.Reverse())
 049    {
 050        pipeline.Use(middleware);
 051    }
 052
 053    return pipeline;
 054});
 55
 56// Broker and database connections
 057builder.Services.AddSingleton<IMessageBrokerFactory>(sp =>
 058{
 059    // Get RabbitMQ connection configuration from DI
 060    var connectionConfiguration = sp.GetRequiredService<IOptions<RabbitMQConnectionConfiguration>>().Value;
 061    return new MessageBrokerFactory(connectionConfiguration);
 062});
 063builder.Services.AddDbContext<AppDbContext, ReadOnlyAppDbContext>(
 064    (sp, options) =>
 065    {
 066        // Get Postgres connection configuration from DI
 067        var postgresConfig = sp.GetRequiredService<IOptions<PostgresConnectionConfiguration>>().Value;
 068        options.UseNpgsql(postgresConfig.ToConnectionString());
 069    }
 070);
 71
 072var app = builder.Build();
 73
 74// Configure the HTTP request pipeline.
 075if (app.Environment.IsDevelopment())
 76{
 77    //  Go to http://localhost:5200/swagger/index.html to test the API
 078    app.UseSwagger();
 079    app.UseSwaggerUI(c =>
 080    {
 081        c.SwaggerEndpoint("/swagger/v1/swagger.json", "ClientManager API v1");
 082    });
 83}
 84
 085app.UseAuthorization();
 086app.MapControllers();
 087app.MapHub<NotificationHub>("/notifications");
 088app.MapControllers();
 089app.MapHealthChecks("/health");
 90
 091app.UseCors(options => options.WithOrigins("http://localhost:5173").AllowAnyMethod().AllowAnyHeader().AllowCredentials()
 92
 093app.Run();

Methods/Properties

<Main>$(System.String[])