开发者

In MS MVC, are Poco classes to be defined in the Models namespace but outside of a repository class?

I think I am very close to assembling an MVC repository correctly but just falling apart at the fringe. I created an MVC project with a repository and am returning data successfully, but not accurately as it pertains to DDD. Please tell me where I am incorrect in terms of strict DDD assembly. I guess if the topics are too wide, a book suggestion would be fine. I hope that I am specific 开发者_StackOverflow中文版enough in my question.

This was one question but I separated them for clarity: Do you create a single namespace for all repository classes called MyStore.Models? Create a repository class for each entity like Product within the Models namespace? Do you put the Pocos in their own classes in the Models namespace but not part of the Repository class itself?

I am currently using Pocos to cut out entities from Linq statements, returning groups of them within IQueryable wrappers like so. I guess here you would somehow remove the IQueryable and replace it with some type of Lazy load? How do you lazy load without being dependent on the original Linq to Sql?

public IQueryable<Product> GetProducts(...) {
return (from p in db.Products
        where ...
        select new myProductPoco {  // Cut out a Poco from Linq
            ID = p.ID,
            Name = p.Name,
            ...
        });
}

Then reference these in MVC views within the inherit page directive:

System.Web.Mvc.ViewPage<IQueryable<MyStore.Models.Product>>

However, the nested generics looks wrong. I assume this requires a re-factor. Where do you define View Model classes that contain references to Entities? Within the controller class (nested class)?


As book suggestions, try Eric Evan's Domain-Driven Design, and maybe Martin Fowler's Refactoring.


Also try Domain Driven Design Quickly produced by InfoQ. It's free to download or $30 in print.

"Domain-Driven Design Quickly was produced by InfoQ.com, summarized primarily by Abel Avram and with Floyd Marinescu as managing editor. Special thanks to Eric Evans for his support and Vladimir Gitlevich and Dan Bergh Johnsson for their detailed reviews. The intention of this book is to get an introduction to Domain-Driven Design into as many hands as possible, to help it become mainstream." -- InfoQ

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜