DependencyInjection.cs for Infrastructure layer
This commit is contained in:
		
							
								
								
									
										33
									
								
								SchengenVisaApi/Infrastructure/DependencyInjection.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								SchengenVisaApi/Infrastructure/DependencyInjection.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,33 @@ | ||||
| using Infrastructure.Database; | ||||
| using Infrastructure.Database.Applicants.Repositories; | ||||
| using Infrastructure.Database.Generic; | ||||
| using Infrastructure.Database.Locations.Repositories.Cities; | ||||
| using Infrastructure.Database.Locations.Repositories.Countries; | ||||
| using Infrastructure.Database.VisaApplications.Repositories; | ||||
| using Microsoft.EntityFrameworkCore; | ||||
| using Microsoft.Extensions.DependencyInjection; | ||||
| using DbContext = Infrastructure.Database.DbContext; | ||||
|  | ||||
| namespace Infrastructure | ||||
| { | ||||
|     public static class DependencyInjection | ||||
|     { | ||||
|         public static IServiceCollection AddInfrastructure(this IServiceCollection services) | ||||
|         { | ||||
|             //TODO строка подключения | ||||
|             services.AddDbContext<DbContext>(opts => | ||||
|                 opts.UseSqlServer("Data Source=(localdb)\\MSSQLLocalDB;Initial Catalog=visadb;Integrated Security=True;")); | ||||
|  | ||||
|             services.AddScoped<IGenericReader>(serviceProvider => serviceProvider.GetRequiredService<DbContext>()); | ||||
|             services.AddScoped<IGenericWriter>(serviceProvider => serviceProvider.GetRequiredService<DbContext>()); | ||||
|             services.AddScoped<IUnitOfWork>(serviceProvider => serviceProvider.GetRequiredService<DbContext>()); | ||||
|  | ||||
|             services.AddScoped<IApplicantsRepository, ApplicantsRepository>(); | ||||
|             services.AddScoped<IVisaApplicationsRepository, VisaApplicationsRepository>(); | ||||
|             services.AddScoped<ICitiesRepository, CitiesRepository>(); | ||||
|             services.AddScoped<ICountriesRepository, CountriesRepository>(); | ||||
|  | ||||
|             return services; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -13,6 +13,7 @@ | ||||
|     <ItemGroup> | ||||
|       <PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0-preview.7.24405.3" /> | ||||
|       <PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0-preview.7.24405.3" /> | ||||
|       <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0-preview.7.24405.3" /> | ||||
|     </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user