开发者

Where is the best place to put validation logic given this application design?

开发者 https://www.devze.com 2023-01-19 13:43 出处:网络
Consider an ASP.NET MVC 2 web application project that uses EF4 POCO entities and the repository pattern to store information in a SQL Server database. So far there are 3 projects, 4 if you count the

Consider an ASP.NET MVC 2 web application project that uses EF4 POCO entities and the repository pattern to store information in a SQL Server database. So far there are 3 projects, 4 if you count the database:

1.) Domain.dll, has no dependencies, exposes POCO's and repository interfaces.

2.) Storage.dll, depends on Domain, implements repository interfaces (using EF 4).

3.) Mvc.dll, depends on both #1 and #2, provides UI layer.

4.) SQL Server database + connection, dll agnostic (no dependencies).

Let's say I add another web application to host a WCF Data Service, which provides an OData feed of the database using Domain.dll and Storage.dll:

5.) Provider.dll, depends on Domain & Storage, provides OData service layer.

开发者_JAVA技巧

Where does the domain validation logic belong in this solution? If the domain POCO classes are decorated with validation attributes, does the WCF data service need anything else to protect the data? Is it ever a good/bad idea to put validation logic into stored procedures, and why?


I would say put DataAttributes on the Domain and use the validation in MVC for the MVC part and use Ent Lib to do the validation in the WCF Service. Alternatively you could use the Ent Live validation in both MVC and WCF, but thats not what this is about. I dont know that this needs to come down to DDD semantics. MVC does validation on the Models when they have DataAttributes, so follow that and do the same in WCF.


I marked this as subjective and argumentative because even the DDD community can't make up its mind about this.

How many layers do you need to change if a new validation requirement for Customer.LastName comes in? Can the UI layer inform the user the domain, wcf, web, database layers have rejected their commands? How is a LastName restriction that a LastName can't exceed 50 characters part of the business domain?

You can see that this is really a discussion and not a answerable question.


Also if your using OData as a Database feed for your services you are not using DDD. You are using Persistance-As-Model or DDD-Lite. This is actually harmful and results in questions like this that try to resolve the problems with using two incompatible patterns together.

0

精彩评论

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