This commit is contained in:
Mikhail Kuznetsov
2023-06-01 16:42:44 +10:00
parent f0d28c0802
commit e465932222
29 changed files with 206 additions and 34 deletions

View File

@@ -0,0 +1,28 @@
using PARR.API.Services.Implementations;
using PARR.API.Services.Interfaces;
namespace PARR.API.Installers
{
/// <summary>
/// Самописные сервисы которые используются для АПИ
/// </summary>
public static class ApiServicesInstaller
{
public static void InstallApiServices(this IServiceCollection services, IConfiguration configuration)
{
services.AddSingleton<IUriService>(provider =>
{
var accessor = provider.GetRequiredService<IHttpContextAccessor>();
var request = accessor.HttpContext.Request;
var absoluteUri = string.Concat(request.Scheme, "://", request.Host.ToUriComponent(), "/");
return new UriService(absoluteUri);
});
//services.AddTransient<IFileService, FileService>();
}
}
}

View File

@@ -0,0 +1,25 @@
using PARR.API.Settings;
namespace PARR.API.Installers
{
public static class CorsInstaller
{
public static void InstallCorsServices(this IServiceCollection services)
{
services.AddCors();
}
public static void InstallCors(this WebApplication app, WebApplicationBuilder builder)
{
var corsSettings = new CorsSettings();
builder.Configuration.GetSection(nameof(CorsSettings)).Bind(corsSettings);
app.UseCors(opt =>
opt.WithOrigins(corsSettings.AllowHostsArray)
.AllowAnyHeader()
.AllowAnyMethod()
);
}
}
}

View File

@@ -0,0 +1,17 @@
namespace PARR.API.Installers
{
/// <summary>
/// Биндинги из конфига appsettings
/// </summary>
public static class SettingsInstaller
{
public static void InstallSettings(this IServiceCollection services, IConfiguration configuration)
{
//var storageSettings = new StorageSettings();
//configuration.GetSection(nameof(StorageSettings)).Bind(storageSettings);
//services.AddSingleton(storageSettings);
//TODO: add other
}
}
}

View File

@@ -0,0 +1,47 @@
using Microsoft.OpenApi.Models;
using System.Reflection;
namespace PARR.API.Installers
{
public static class SwaggerInstaller
{
public static void InstallSwaggerService(this IServiceCollection services, IConfiguration configuration)
{
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
services.AddEndpointsApiExplorer();
var version = Assembly.GetEntryAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion ?? "1.0.0";
services.AddSwaggerGen(x =>
{
//TODO:
x.SwaggerDoc(
"v1",
new OpenApiInfo
{
Title = "GEO API",
Version = $"v{version}",
Description = "API for the project \"GEO DVGD\"",
Contact = new OpenApiContact { Email = "IVC_TrubnikovME@dvgd.rzd;IVC_KuznetsovMV@dvgd.rzd", Name = "Trubnikov M.E., Kuznetsov M.V." },
License = new OpenApiLicense { Name = "© PTK-DVGD Software LLC" }
});
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
x.IncludeXmlComments(xmlPath);
});
}
public static void InstallSwagger(this WebApplication app)
{
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}
}
}
}