Moved registering services to separated class

This commit is contained in:
2024-08-13 17:53:22 +03:00
parent cc7eb1d168
commit a77a8339d7
4 changed files with 27 additions and 9 deletions

View File

@@ -0,0 +1,22 @@
using System.Reflection;
namespace SchengenVisaApi
{
/// Provides methods to add services to DI-container
public static class DependencyInjection
{
/// Add needed services
public static IServiceCollection RegisterServices(this IServiceCollection services)
{
services.AddControllers();
services.AddEndpointsApiExplorer();
services.AddSwaggerGen(options =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
return services;
}
}
}

View File

@@ -1,5 +1,3 @@
using System.Reflection;
namespace SchengenVisaApi; namespace SchengenVisaApi;
#pragma warning disable CS1591 #pragma warning disable CS1591
@@ -8,13 +6,7 @@ public class Program
public static void Main(string[] args) public static void Main(string[] args)
{ {
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers(); builder.Services.RegisterServices();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
var app = builder.Build(); var app = builder.Build();
app.UseSwagger(); app.UseSwagger();

View File

@@ -12,4 +12,8 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/> <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/>
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ApplicationLayer\ApplicationLayer.csproj" />
</ItemGroup>
</Project> </Project>