Hi, We are implementing a SignalR service that needs to write e read from database and is authenticated. There are some best practices to deal with database ? We are experiencing some "object disposed" exception accessing to database.
I've looked at your Chat module and I've seen then some time the UnitOfWork attribute is used but not always. Can you lead me on the correct way?
Thank you
4 Answer(s)
-
0
I've looked at your Chat module and I've seen then some time the UnitOfWork attribute is used but not always.
Can you point out the specific code?
Can you lead me on the correct way?
Controllers, application services, domain services, repositories, etc. all use work units, so it is recommended that you always use it.
https://aspnetboilerplate.com/Pages/Documents/Unit-Of-Work
-
0
In ChatMessageManager, Save and GetUnreadMessageCount have the UnitOfWork attribute, while FindMessageAsync hasn't. Why ?
Anyway, reading with more attention, your link gave me some response to my questions.
Thank you
-
0
In addition to atomic processing, UnitOfWork also undertakes tenant management.
In Save and GetUnreadMessageCount, Uow is used to query database with tenant id.
For example;
[UnitOfWork] public virtual long Save(ChatMessage message) { using (CurrentUnitOfWork.SetTenantId(message.TenantId)) { return _chatMessageRepository.InsertAndGetId(message); } }
This will insert message by considering message.TenantId.
But in FindMessageAsync method no need to consider about tenant id and/or any atomic processing.
public async Task<ChatMessage> FindMessageAsync(int id, long userId) { return await _chatMessageRepository.FirstOrDefaultAsync(m => m.Id == id && m.UserId == userId); }
-
0
Thank you @demirmusa I think that now I have a complete picture of the behaviour.