cicd
This commit is contained in:
28
PARR.API/Installers/ApiServicesInstaller.cs
Normal file
28
PARR.API/Installers/ApiServicesInstaller.cs
Normal 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>();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
25
PARR.API/Installers/CorsInstaller.cs
Normal file
25
PARR.API/Installers/CorsInstaller.cs
Normal 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()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
17
PARR.API/Installers/SettingsInstaller.cs
Normal file
17
PARR.API/Installers/SettingsInstaller.cs
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
47
PARR.API/Installers/SwaggerInstaller.cs
Normal file
47
PARR.API/Installers/SwaggerInstaller.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user