Moved registering services to separated class
This commit is contained in:
		
							
								
								
									
										22
									
								
								SchengenVisaApi/SchengenVisaApi/DependencyInjection.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								SchengenVisaApi/SchengenVisaApi/DependencyInjection.cs
									
									
									
									
									
										Normal 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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -1,5 +1,3 @@ | ||||
| using System.Reflection; | ||||
|  | ||||
| namespace SchengenVisaApi; | ||||
|  | ||||
| #pragma warning disable CS1591 | ||||
| @@ -8,13 +6,7 @@ public class Program | ||||
|     public static void Main(string[] args) | ||||
|     { | ||||
|         var builder = WebApplication.CreateBuilder(args); | ||||
|         builder.Services.AddControllers(); | ||||
|         builder.Services.AddEndpointsApiExplorer(); | ||||
|         builder.Services.AddSwaggerGen(options => | ||||
|         { | ||||
|             var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; | ||||
|             options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); | ||||
|         }); | ||||
|         builder.Services.RegisterServices(); | ||||
|  | ||||
|         var app = builder.Build(); | ||||
|             app.UseSwagger(); | ||||
|   | ||||
| @@ -12,4 +12,8 @@ | ||||
|         <PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0"/> | ||||
|     </ItemGroup> | ||||
|  | ||||
|     <ItemGroup> | ||||
|       <ProjectReference Include="..\ApplicationLayer\ApplicationLayer.csproj" /> | ||||
|     </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user