Skip to content

Commit 5b076a6

Browse files
committed
Added an exception andling for the time in which the _baseRepo is null in EFCoreStorageBusinessService
1 parent 713bff1 commit 5b076a6

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

MZBase.EntityFrameworkCore/EFCoreStorageBusinessService.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ ILogger<DomainModel> logger
2727
_unitOfWork = unitOfWork;
2828
_baseRepo = _unitOfWork.GetRepo<DomainModel, DBModelEntity, PrimaryKeyType>();
2929
}
30+
private void _chackBaseRepo()
31+
{
32+
if (_baseRepo == null)
33+
{
34+
throw new ServiceException($"baseRepo was null. Make sure that the related {nameof(IBaseLDRCompatibleRepositoryAsync<DomainModel, DBModelEntity, PrimaryKeyType>)} is instantiated properly in the constructor of the related UoW and also is properly retuned in GetRep() method");
35+
}
36+
}
3037
public override async Task<PrimaryKeyType> AddAsync(DomainModel item)
3138
{
3239
if (item == null)
@@ -35,9 +42,9 @@ public override async Task<PrimaryKeyType> AddAsync(DomainModel item)
3542
LogAdd(null, null, ex);
3643
throw ex;
3744
}
38-
45+
_chackBaseRepo();
3946
await ValidateOnAddAsync(item);
40-
47+
4148
var g = _baseRepo.Insert(item);
4249
try
4350
{
@@ -62,7 +69,7 @@ public override async Task ModifyAsync(DomainModel item)
6269
LogModify(item, null, exception);
6370
throw exception;
6471
}
65-
72+
_chackBaseRepo();
6673
var currentItem = await _baseRepo.GetByIdAsync(item.ID);
6774
if (currentItem == null)
6875
{
@@ -101,6 +108,7 @@ public override async Task ModifyAsync(DomainModel item)
101108
}
102109
public override async Task RemoveByIdAsync(PrimaryKeyType ID)
103110
{
111+
_chackBaseRepo();
104112
var itemToDelete = await _baseRepo.FirstOrDefaultAsync(ss => ss.ID.Equals(ID));
105113

106114
if (itemToDelete == null)
@@ -125,6 +133,7 @@ public override async Task RemoveByIdAsync(PrimaryKeyType ID)
125133
}
126134
public override async Task<DomainModel> RetrieveByIdAsync(PrimaryKeyType ID)
127135
{
136+
_chackBaseRepo();
128137
DBModelEntity? item;
129138
try
130139
{
@@ -146,6 +155,7 @@ public override async Task<DomainModel> RetrieveByIdAsync(PrimaryKeyType ID)
146155
}
147156
public override async Task<LinqDataResult<DomainModel>> ItemsAsync(LinqDataRequest request)
148157
{
158+
_chackBaseRepo();
149159
try
150160
{
151161
var f = await _baseRepo.AllItemsAsync(request);

MZBase.EntityFrameworkCore/MZBase.EntityFrameworkCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7-
<Version>2.0.4</Version>
7+
<Version>2.0.5</Version>
88
<AssemblyVersion>1.0.1.1</AssemblyVersion>
99
<Authors>Mahdi Zandakbari</Authors>
1010
<Description>An EFCore implementation of some of the more common interfaces of MZBase.Infrustructure.

0 commit comments

Comments
 (0)