Username exists check in ViewModel/DomainModel?
I have ViewModel for Insert/Update/Delete. DI done on controller with Ninject implementing respository patter.
I am little confused. I have UserCreateViewModel bind to Create.aspx once submi开发者_JS百科tted need to check UserName already in DB.
For 1 and 2 I need Constructor DI to call IsUserRegistered method from respository.
1- ViewModel.
2- domain model.
3- service layer. Is it right to add extra layer on to check UserName exists in DB?
4- Someone suggested to use Attribute for that and DI in that.
There should definitely be a method to perform the check within your domain model! That's where it belongs, it's pure business logic to perform that check. Additionally, there should probably be constraints on the datasource and the mapped entities to enforce this rule.
Call the method then from the ViewModel.
Regarding the service-layer: This is usually just a facade to expose domain-layer functionality. If you want to consume this method via a service-client, then expose it.
精彩评论