Skip to content

Commit 589ab02

Browse files
add repository registration extension method
1 parent 23f52e1 commit 589ab02

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using Microsoft.Extensions.DependencyInjection;
2+
using PaymentCoreServiceApi.Core.Interfaces.Repositories.Write;
3+
using PaymentCoreServiceApi.Infrastructure.Repositories.Write;
4+
5+
namespace PaymentCoreServiceApi.Infrastructure.Extensions;
6+
7+
public static class ServiceCollectionExtensions
8+
{
9+
public static IServiceCollection AddRepositories(this IServiceCollection services)
10+
{
11+
// Register Base Repositories
12+
services.AddScoped(typeof(IBaseWriteOnlyRepository<>), typeof(EfBaseWriteOnlyRepository<>));
13+
14+
// Register Domain Specific Repositories
15+
services.AddScoped<IUserWriteRepository, UserWriteRepository>();
16+
17+
return services;
18+
}
19+
}

Program.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
using System.Reflection;
22
using Microsoft.EntityFrameworkCore;
33
using PaymentCoreServiceApi.Infrastructure.DbContexts;
4-
using PaymentCoreServiceApi.Core.Interfaces.Repositories.Write;
5-
using PaymentCoreServiceApi.Core.Interfaces.Repositories.IUnitOfWork;
6-
using PaymentCoreServiceApi.Infrastructure.Repositories.Write;
7-
using PaymentCoreServiceApi.Infrastructure.Repositories.UnitOfWork;
4+
using PaymentCoreServiceApi.Infrastructure.Extensions;
85
using MediatR;
96

107
var builder = WebApplication.CreateBuilder(args);
@@ -21,8 +18,7 @@
2118
builder.Services.AddMediatR(Assembly.GetExecutingAssembly());
2219

2320
// Register Repositories
24-
builder.Services.AddScoped(typeof(IBaseWriteOnlyRepository<>), typeof(EfBaseWriteOnlyRepository<>));
25-
builder.Services.AddScoped<IUserWriteRepository, UserWriteRepository>();
21+
builder.Services.AddRepositories();
2622

2723
var app = builder.Build();
2824

0 commit comments

Comments
 (0)