SPMS_API/SPMS.Infrastructure/DependencyInjection.cs
SEAN cd8270c5c0 feat: DI 컨테이너 및 서비스 등록 구조화 (#26)
- Infrastructure/DependencyInjection.cs: AddInfrastructure() 확장 메서드
- Application/DependencyInjection.cs: AddApplication() 확장 메서드
- API/Extensions/ApplicationBuilderExtensions.cs: UseMiddlewarePipeline() 확장 메서드
- Program.cs 정리 (DI/파이프라인 분리)

Closes #26
2026-02-09 16:25:44 +09:00

33 lines
1.0 KiB
C#

using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using SPMS.Application.Interfaces;
using SPMS.Domain.Interfaces;
using SPMS.Infrastructure.Auth;
using SPMS.Infrastructure.Persistence;
using SPMS.Infrastructure.Persistence.Repositories;
namespace SPMS.Infrastructure;
public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(
this IServiceCollection services,
IConfiguration configuration)
{
// DbContext
var connectionString = configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<AppDbContext>(options =>
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString)));
// UnitOfWork & Repositories
services.AddScoped<IUnitOfWork, UnitOfWork>();
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
// External Services
services.AddScoped<IJwtService, JwtService>();
return services;
}
}