-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathDependencyInjectionExtensions.cs
More file actions
58 lines (51 loc) · 2.07 KB
/
DependencyInjectionExtensions.cs
File metadata and controls
58 lines (51 loc) · 2.07 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (c) TotalSoft.
// This source code is licensed under the MIT license.
using System.Collections.Generic;
using System.Linq;
using Microsoft.EntityFrameworkCore;
using NBB.Core.Abstractions;
using NBB.Data.Abstractions;
using NBB.Data.EntityFramework;
using NBB.Data.EntityFramework.Internal;
// ReSharper disable once CheckNamespace
namespace Microsoft.Extensions.DependencyInjection
{
public static class DependencyInjectionExtensions
{
public static void AddEntityFrameworkDataAccess(this IServiceCollection services)
{
services.AddSingleton<IExpressionBuilder, ExpressionBuilder>();
}
public static void AddEfCrudRepository<TEntity, TContext>(this IServiceCollection services)
where TEntity : class
where TContext : DbContext
{
services.AddScoped<ICrudRepository<TEntity>, EfCrudRepository<TEntity, TContext>>();
services.AddEfUow<TEntity, TContext>();
}
public static void AddEfReadOnlyRepository<TEntity, TContext>(this IServiceCollection services)
where TEntity : class
where TContext : DbContext
{
services.AddScoped<IReadOnlyRepository<TEntity>, EfReadOnlyRepository<TEntity, TContext>>();
}
public static void AddEfAsyncEnumerable<TEntity, TContext>(this IServiceCollection services)
where TEntity : class
where TContext : DbContext
{
services.AddScoped<IAsyncEnumerable<TEntity>, EfQuery<TEntity, TContext>>();
}
public static void AddEfQuery<TEntity, TContext>(this IServiceCollection services)
where TEntity : class
where TContext : DbContext
{
services.AddScoped<IQueryable<TEntity>, EfQuery<TEntity, TContext>>();
}
public static void AddEfUow<TEntity, TContext>(this IServiceCollection services)
where TEntity : class
where TContext : DbContext
{
services.AddScoped<IUow<TEntity>, EfUow<TEntity, TContext>>();
}
}
}