-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnitOfWorkServiceCollectionExtensions.cs
More file actions
36 lines (30 loc) · 1.3 KB
/
Copy pathUnitOfWorkServiceCollectionExtensions.cs
File metadata and controls
36 lines (30 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
namespace Dreamless.Core
{
public static class UnitOfWorkServiceCollectionExtensions
{
public static IServiceCollection AddUnitOfWork<TContext>(this IServiceCollection services) where TContext : DbContext
{
services.AddScoped<IRepositoryFactory, UnitOfWork<TContext>>();
services.AddScoped<IUnitOfWork, UnitOfWork<TContext>>();
services.AddScoped<IUnitOfWork<TContext>, UnitOfWork<TContext>>();
return services;
}
public static IServiceCollection AddUnitOfWork<TContext1, TContext2>(this IServiceCollection services)
where TContext1 : DbContext
where TContext2 : DbContext
{
services.AddScoped<IUnitOfWork<TContext1>, UnitOfWork<TContext1>>();
services.AddScoped<IUnitOfWork<TContext2>, UnitOfWork<TContext2>>();
return services;
}
public static IServiceCollection AddCustomRepository<TEntity, TRepository>(this IServiceCollection services)
where TEntity : class
where TRepository : class, IRepository<TEntity>
{
services.AddScoped<IRepository<TEntity>, TRepository>();
return services;
}
}
}