使用实体框架的参数化 POCO 构造函数
执着无明是指存在 能够允许开发者编写 并以这样的方式测试域对象 完全独立于基本面 可能的要求和假设 由基础设施服务制作 (在本例中为实体框架)。 此类要求/假设可能 通常包括:
- 需要实现特定接口(例如 IPOCO)
- 从基类继承
- 提供特定的构造函数
- 对象实例化/构造要求 - 使用特定工厂 例如**
- 需要元数据或映射类或属性属性
- 需要使用特定的关系机制
这相当于能够使用 普通旧 CLR 对象 (POCO),以便 开发者可以创作他们的域名 没有任何假设的对象和 框架提出的要求。 使用这种方法,一旦域 对象已准备好 满意,开发者可以使用 这些类与实体 关系框架 数据库访问和持久性。
截至目前(CTP5),是否有任何方法可以使用参数化构造函数来重构 poco?如果不是,就很难看出实体框架如何提供持久性无知。
According to Initial POCO Design 1-Pager
Persistence Ignorance refers to being
able to allow the developer to write
and test domain objects in a way that
is entirely independent of fundamental
requirements and assumptions that may
be made by the infrastructure service
(in this case, the Entity Framework).
Such requirements / assumptions may
often include:
- The need to implement a specific interface (for e.g., IPOCO)
- Inheritance from a base class
- Providing specific constructors
- Object Instantiation/Construction requirements – use a specific factory
for instance**- The need for metadata or mapping class or property Attributes
- The need to use specific relationship mechanisms
This amounts to being able to use
Plain Old CLR Objects (POCO) so that a
developer can author their domain
objects free of all assumptions and
requirements imposed by the framework.
Using this approach, once the domain
objects are ready to their
satisfaction, the developer can use
these classes with the Entity
Framework in order for relational
database access and persistence.
As of right now (CTP5), is there any way at all to reconstitute a poco using a parametrized constructor? If not, it's hard to see how the Entity Framework can be said to offer persistence ignorance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以拥有任意多个参数化构造函数,只要框架可以访问无参数构造函数即可,如果您没有构造函数,或者除了您创建的参数化构造函数之外还提供了一个,则默认情况下可用。
You can have as many parameterized constructors as you want, so long as the framework has access to a parameter-less one, which is available by default if you you have no constructors, or if you provide one in addition to the parameterized ones you create.