kgrzybek / modular-monolith-with-ddd

Full Modular Monolith application with Domain-Driven Design approach.
MIT License
10.89k stars 1.71k forks source link

Async methods in domain service #201

Closed sreejith-ms closed 3 years ago

sreejith-ms commented 3 years ago

The method CountUsersWithLogin in IUsersCounter is synchronous, how to make it async?

I have introduced IsBrokenAsync to resolve this and it will introduce async methods in the domain model. This seems to be a bad idea after reading this domain model purity article. Is this the reason behind the method CountUsersWithLogin created as synchronous?

Any thoughts on how to handle this?

kgrzybek commented 3 years ago

Hi @sreejith-ms

We just need to live with it. I mean the ideal solution is to count users in the application layer and provide this count to the domain. But sometimes for performance reasons, this is not an optimal solution and then you can use method injection. I don't like async/await in Domain Model so I would rather stick with sync and change to async if a performance issue will appear.

sreejith-ms commented 3 years ago

Thanks @kgrzybek