Skip to content

Commit 89bdb8e

Browse files
author
raihanM95
committed
RepositoryBase implemented
1 parent ffc761e commit 89bdb8e

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed

Application/Application.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<ProjectReference Include="..\Domain\Domain.csproj" />
9+
</ItemGroup>
10+
711
<ItemGroup>
812
<Folder Include="Interfaces\" />
913
</ItemGroup>

Application/IRepositoryBase.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Linq.Expressions;
5+
using System.Text;
6+
7+
namespace Application
8+
{
9+
public interface IRepositoryBase<T>
10+
{
11+
IQueryable<T> FindAll();
12+
IQueryable<T> FindByCondition(Expression<Func<T, bool>> expression);
13+
void Create(T entity);
14+
void Update(T entity);
15+
void Delete(T entity);
16+
}
17+
}

Infrastructure.Service/Infrastructure.Service.csproj

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,9 @@
88
<Folder Include="Repositories\" />
99
</ItemGroup>
1010

11+
<ItemGroup>
12+
<ProjectReference Include="..\Application\Application.csproj" />
13+
<ProjectReference Include="..\Infrastructure.Persistence\Infrastructure.Persistence.csproj" />
14+
</ItemGroup>
15+
1116
</Project>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Application;
2+
using Infrastructure.Persistence.Contexts;
3+
using Microsoft.EntityFrameworkCore;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Linq.Expressions;
8+
using System.Text;
9+
10+
namespace Infrastructure.Service
11+
{
12+
public abstract class RepositoryBase<T> : IRepositoryBase<T> where T : class
13+
{
14+
protected RepositoryContext RepositoryContext { get; set; }
15+
public RepositoryBase(RepositoryContext repositoryContext)
16+
{
17+
this.RepositoryContext = repositoryContext;
18+
}
19+
public IQueryable<T> FindAll()
20+
{
21+
return this.RepositoryContext.Set<T>().AsNoTracking();
22+
}
23+
public IQueryable<T> FindByCondition(Expression<Func<T, bool>> expression)
24+
{
25+
return this.RepositoryContext.Set<T>().Where(expression).AsNoTracking();
26+
}
27+
public void Create(T entity)
28+
{
29+
this.RepositoryContext.Set<T>().Add(entity);
30+
}
31+
public void Update(T entity)
32+
{
33+
this.RepositoryContext.Set<T>().Update(entity);
34+
}
35+
public void Delete(T entity)
36+
{
37+
this.RepositoryContext.Set<T>().Remove(entity);
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)