Hello, in this source code below, the class already inherits from MyTestsDomainServiceBase, hence, all methods are handled automatically by UOW.
Why the code still adds an attribute [UnitOfWork], is it necessary in this case?
Thanks
public class FriendshipManager : MyTestsDomainServiceBase, IFriendshipManager
{
private readonly IRepository<Friendship, long> _friendshipRepository;
public FriendshipManager(IRepository<Friendship, long> friendshipRepository)
{
_friendshipRepository = friendshipRepository;
}
[UnitOfWork]
public void CreateFriendship(Friendship friendship)
{
if (friendship.TenantId == friendship.FriendTenantId &&
friendship.UserId == friendship.FriendUserId)
{
throw new UserFriendlyException(L("YouCannotBeFriendWithYourself"));
}
using (CurrentUnitOfWork.SetTenantId(friendship.TenantId))
{
_friendshipRepository.Insert(friendship);
CurrentUnitOfWork.SaveChanges();
}
}
6 Answer(s)
-
0
Hi,
Normally you don't need this but I couldn't remember why we did this at the moment. I will check this and let you know. You can remove it and try chat functionality in the mean time.
Thanks.
-
0
Hi,
Sorry for the late reply, Normally Domain Services are not UoW by default, that is why UnitOfWork attribute is used.
Thanks.
-
0
Thank you. I understand now. Why would DS not be UOW?
-
0
Hi,
Because domain services are mostly used in app services/controllers and cannot be reached from UI directly. Since app services and controllers are unit of work by default, there is no need to make domain services UoW by default.
Thanks.
-
0
Just FYI, here you can read more about the implementation of UOW :)
<a class="postlink" href="https://www.aspnetboilerplate.com/Pages/Documents/Unit-Of-Work">https://www.aspnetboilerplate.com/Pages ... it-Of-Work</a>
-
0
Thanks everyone.