Centralize repository service registrations in Infrastructure's DependencyInjection.cs for better maintainability and separation of concerns. Remove direct registrations from Program.cs and add necessary using statements.
27 lines
1.0 KiB
C#
27 lines
1.0 KiB
C#
using DbFirst.Application.Repositories;
|
|
using DbFirst.Infrastructure.Repositories;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace DbFirst.Infrastructure;
|
|
|
|
public static class DependencyInjection
|
|
{
|
|
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
|
|
{
|
|
services.Configure<TableConfigurations>(configuration.GetSection("TableConfigurations"));
|
|
services.AddDbContext<ApplicationDbContext>(options =>
|
|
options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
|
|
|
|
services.AddDbContext<MassDataDbContext>(options =>
|
|
options.UseSqlServer(configuration.GetConnectionString("MassDataConnection")));
|
|
|
|
services.AddScoped<ICatalogRepository, CatalogRepository>();
|
|
services.AddScoped<IMassDataRepository, MassDataRepository>();
|
|
services.AddScoped<ILayoutRepository, LayoutRepository>();
|
|
|
|
return services;
|
|
}
|
|
}
|