asp.net-mvcarchitecturedomain-driven-design

Get an Entity in Save Method, What is correct form?


I'm begginer in asp.net mvc and i have some doubts.

P.S: I'm using DDD to learn

I have an ACtion in a Controller and it'll save an entity (from my model) by a repository (for a database). My doubts is, How can I get the informations from the View and save it by a repository in my Controller ? Is it correct to get an entity of my Model in Save method of controller, like this:

public ActionResult Save(Product product) { // validate object
// save data in repository
return View("Success"); }

Or Need I get an DTO (with a structure similar to my entity) and create an object passing property by property to an entity ? I didnt' like of FormCollection and I'd like to know, What is recommended architecturally ?

Thanks a lot guys

Cheers


Solution

  • I you want to follow DDD practices as described by the Blue Book you should bind your views to DTO's which can be forwarded to a thin 'Application' layer where Domain objects are created or retrieved from database. This application layer can be a simple facade with methods or can leverage command pattern.

    For a live demo, you can see my project -- DDDSample.NET