Hi there!
I have a model Country(title) and CountryAppService inherited from AsyncCrudAppService.
This service is fired from front app in some.js file. Base validation for my creating Dto(Required, MinLength..) work perfectly. But now i want to <ins>check duplicating on insert</ins> for the new country.
As i read about domain services, i should implement domain service CountryManager, inject IReposity<Country> into and implement InsertAsync method, where i can check duplicating and throw UserFreindlyException.
But my AppService don't know about my CountryManager, it's work with IReposity<Country>. I see 2 approaches for resolving this issue:
Create CountryRepository, overriding InsertAsync method with CountryManager using. But i suppose this is bad way because of CountryManager use IReposity<Country> already.
I can override InsertAsync method of my CountryAppService. Is this the right way or more graceful solution exists?
1 Answer(s)
-
0
But my AppService don't know about my CountryManager, it's work with IReposity<Country>
You probably want to say "my AppServicec CAN directly use repository and skip using CountryManager, there is nothing prevent that".
If you say that, you are right. If you follow best practices, I can say that:
- Make constructor of your Country internal.
- Thus, it can not be created from application layer, and therefore from app service.
- Add CountryManager.Create(...) method which checks duplicate and return a Country object.
- Mark Country.Name's setter as protected (I assume that Name will be unique) so no one can set it. Where to set: Country's constructor!
and so on... there can be alternative solutions but this is one of them.