领域驱动设计和Entity Framework 4.1(代码优先) [英] Domain Driven Design and Entity Framework 4.1 (code-first)

查看:138
本文介绍了领域驱动设计和Entity Framework 4.1(代码优先)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在学习领域驱动设计的发展方针,并使用由蒂姆·麦卡锡C#的书为指导.NET领域驱动设计。

I am currently learning the domain driven design approach to development and using the .NET Domain Driven Design with C# book by Tim McCarthy as a guide.

这本书真正有用的,但我变得有点脱胶,当谈到使用实体框架,特别是在4.1中可用的代码优先方法。

The book is really helpful but I'm becoming a bit unstuck when it comes to using the entity framework, in particular the code-first approach available in 4.1.

根据上例这本书中,分层的体系结构方法应该指的是基础设施层不能看到模型/域之一。

Based on the example in the book, the layered architecture approach should mean the infrastructure layer can't see the model/domain one.

那么什么是映射我的域名POCO的在数据库的最佳方法这(我假设)上下文类应该坐在在基础设施层,没有违反分层的方法?

So what's the best approach to mapping my domain poco's in the db context classes which (I assume) should sit in the infrastructure layer, without contravening the layered approach?

有一个很好的机会,我完全错了我的想法,所以请让!我知道,因为我仍然在学习

There's a good chance I'm completely wrong with my thinking so please let me know as I'm still learning!

非常感谢:)

亚当

推荐答案

好最ORM的今天,像EF 4.1和NHibernate(流利Nhibenrate插件)可以通过映射类描述了从POCO为DB语境映射。这些映射类shpuld最好的ORM会话特定的类被放置在基础设施数据库项目,也许在一起。

Well most ORM's today, like EF 4.1 and Nhibernate (fluent Nhibenrate addon) can describe mappings from POCO to Db context through mapping classes. These mapping classes shpuld best be placed in an infrastructural database project, maybe together with ORM session specific classes.

那么你的POCO领域类应该放置在域项目不该'T有其他组件或项目的任何引用。但基础数据库项目应引用域,使您的映射类可以descibe如何POCO的应该从一个持久状态被装载。

Then your POCO domain classes should be placed in a Domain project that shouldn't have any references to other components or projects. BUT the infrastructural database project should reference the domain so that your mapping classes can descibe how POCO's should be loaded from a persisted state.

一起使用大量依赖注入的用良好而稳固的IoC框架(温莎城堡......)。这将帮助你放松的事了一点点。其更好地依赖抽象/接口,而不是在执行

Use a lot of Dependency injection together with a good and solid IoC framework (Windsor Castle...). This will help you to loosen things up a little bit. Its better to depend on an abstraction/interface rather than an implementation.

下面是基础
http://www.infoq.com/articles/ddd-in-practice

但好事你决定去代码优先的方法。我真的建议这种方法,如果你有选择。但有时,当旧的遗留系统产生干扰,事情并不那么容易。

But good thing you decided to go for the Code First approach. I really recommend that approach if you have the option. But sometimes when old legacy systems interfere, things aren't that easy.

这篇关于领域驱动设计和Entity Framework 4.1(代码优先)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆