academia/src/backend/Adapters/Driven/Persistence/DependencyInjection.cs

30 lines
1.1 KiB
C#
Raw Normal View History

namespace Adapters.Driven.Persistence;
using Adapters.Driven.Persistence.Context;
using Adapters.Driven.Persistence.Repositories;
using Domain.Ports.Repositories;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
public static class DependencyInjection
{
public static IServiceCollection AddPersistence(
this IServiceCollection services,
IConfiguration configuration)
{
services.AddDbContext<AppDbContext>(options =>
options.UseSqlServer(
configuration.GetConnectionString("DefaultConnection"),
b => b.MigrationsAssembly(typeof(AppDbContext).Assembly.FullName)));
services.AddScoped<IStudentRepository, StudentRepository>();
services.AddScoped<ISubjectRepository, SubjectRepository>();
services.AddScoped<IProfessorRepository, ProfessorRepository>();
services.AddScoped<IEnrollmentRepository, EnrollmentRepository>();
services.AddScoped<IUnitOfWork, UnitOfWork>();
return services;
}
}