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>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Reflection;
|
||||
using Infrastructure;
|
||||
|
||||
namespace SchengenVisaApi
|
||||
{
|
||||
@@ -7,6 +8,15 @@ namespace SchengenVisaApi
|
||||
{
|
||||
/// Add needed services
|
||||
public static IServiceCollection RegisterServices(this IServiceCollection services)
|
||||
{
|
||||
services
|
||||
.AddPresentation()
|
||||
.AddInfrastructure();
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
private static IServiceCollection AddPresentation(this IServiceCollection services)
|
||||
{
|
||||
services.AddControllers();
|
||||
services.AddEndpointsApiExplorer();
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\ApplicationLayer\ApplicationLayer.csproj" />
|
||||
<ProjectReference Include="..\Infrastructure\Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user