mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 05:11:10 +00:00
Adds dependency injection services of the Presentation API layer.
This commit is contained in:
1 parent
ddf9a68f46
commit
75cce8bfb9
2 files changed
+83
-35
No files matched your search
+49
@@ -0,0 +1,49 @@
|
|||||||
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Presentation.Api.Common.Configuration;
|
||||||
|
using Lumina.Presentation.Api.Common.Errors;
|
||||||
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Microsoft.AspNetCore.Mvc.Infrastructure;
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
namespace Lumina.Presentation.Api.Common.DependencyInjection;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Contains all services of the Presentation API layer.
|
||||||
|
/// </summary>
|
||||||
|
public static class PresentationApiLayerServices
|
||||||
|
{
|
||||||
|
#region ===================================================================== METHODS ===================================================================================
|
||||||
|
/// <summary>
|
||||||
|
/// Registers the services of the Presentation API layer into the dependency injection container.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="services">The service collection to add the services to.</param>
|
||||||
|
/// <returns>The service collection with the added services.</returns>
|
||||||
|
public static IServiceCollection AddPresentationApiLayerServices(this IServiceCollection services)
|
||||||
|
{
|
||||||
|
// add services to the container
|
||||||
|
services.AddControllers();
|
||||||
|
|
||||||
|
// add services to the container.
|
||||||
|
services.AddEndpointsApiExplorer();
|
||||||
|
services.AddSwaggerGen();
|
||||||
|
services.ConfigureOptions<ConfigureSwaggerOptions>();
|
||||||
|
|
||||||
|
services.AddApiVersioning(options =>
|
||||||
|
{
|
||||||
|
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||||
|
options.AssumeDefaultVersionWhenUnspecified = true;
|
||||||
|
options.ReportApiVersions = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddVersionedApiExplorer(options =>
|
||||||
|
{
|
||||||
|
options.GroupNameFormat = "'v'VVV";
|
||||||
|
options.SubstituteApiVersionInUrl = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
services.AddSingleton<ProblemDetailsFactory, CustomProblemDetailsFactory>();
|
||||||
|
|
||||||
|
return services;
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
@@ -1,44 +1,43 @@
|
|||||||
var builder = WebApplication.CreateBuilder(args);
|
#region ========================================================================= USING =====================================================================================
|
||||||
|
using Lumina.Presentation.Api.Common.DependencyInjection;
|
||||||
|
using Lumina.Application.Common.DependencyInjection;
|
||||||
|
#endregion
|
||||||
|
|
||||||
// Add services to the container.
|
namespace Lumina.Presentation.Api;
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
||||||
builder.Services.AddEndpointsApiExplorer();
|
|
||||||
builder.Services.AddSwaggerGen();
|
|
||||||
|
|
||||||
var app = builder.Build();
|
/// <summary>
|
||||||
|
/// Application entry point, contains the composition root module, wires up all dependencies of the application.
|
||||||
// Configure the HTTP request pipeline.
|
/// </summary>
|
||||||
if (app.Environment.IsDevelopment())
|
public class Program
|
||||||
{
|
{
|
||||||
app.UseSwagger();
|
#region ===================================================================== METHODS ===================================================================================
|
||||||
app.UseSwaggerUI();
|
/// <summary>
|
||||||
}
|
/// Application entry point.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="args">Optional command line arguments</param>
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
builder.Services.AddApplicationLayerServices();
|
||||||
|
builder.Services.AddPresentationApiLayerServices();
|
||||||
|
|
||||||
var summaries = new[]
|
var app = builder.Build();
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
|
||||||
|
|
||||||
app.MapGet("/weatherforecast", () =>
|
app.UseExceptionHandler("/error"); // uses a middleware which reexecutes the request to the error path
|
||||||
{
|
|
||||||
var forecast = Enumerable.Range(1, 5).Select(index =>
|
|
||||||
new WeatherForecast
|
|
||||||
(
|
|
||||||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
|
||||||
Random.Shared.Next(-20, 55),
|
|
||||||
summaries[Random.Shared.Next(summaries.Length)]
|
|
||||||
))
|
|
||||||
.ToArray();
|
|
||||||
return forecast;
|
|
||||||
})
|
|
||||||
.WithName("GetWeatherForecast")
|
|
||||||
.WithOpenApi();
|
|
||||||
|
|
||||||
app.Run();
|
// configure the HTTP request pipeline.
|
||||||
|
if (app.Environment.IsDevelopment())
|
||||||
|
{
|
||||||
|
app.UseSwagger();
|
||||||
|
app.UseSwaggerUI();
|
||||||
|
}
|
||||||
|
|
||||||
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
app.UseHttpsRedirection();
|
||||||
{
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
app.MapControllers();
|
||||||
|
|
||||||
|
app.Run();
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user