开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜