Fluent nhibernate - 设计问题
关于项目架构实施 fluid-nhibernate 的最佳方法是什么?
我目前有两个项目,一个是领域层,另一个是持久层。我的问题是,当尝试配置 nhibernate 时,我得到了循环引用。
该域引用了持久层,但是如何在不必引用持久层中的域(即 AddFromAssemblyOf() 行中的产品类)的情况下使配置正常工作?
目前我的配置是这样的。
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DisillStoreConnectionString")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()))
.BuildSessionFactory();
What would be the best way to implement fluent-nhibernate regarding project architecture?
I have two projects at the moment one for the domain layer and the other is the persistance layer. My problem is that when trying to configure nhibernate I get a circular reference.
The domain references the persistance layer but how do I get the configuration to work without having to reference the domain in the persistance layer i.e. the product class in this line AddFromAssemblyOf()?
Currently my configuration is like this.
return Fluently.Configure()
.Database(MsSqlConfiguration.MsSql2008.ConnectionString(c => c.FromConnectionStringWithKey("DisillStoreConnectionString")))
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Product>()))
.BuildSessionFactory();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要在持久性项目中使用 ClassMap 类(而不是域模型)来使用 Fluent 配置类。
使用您的代码示例,您需要在
Map
类而不是Model
类上使用AddFromAssemblyOf
。请参阅:这样,您的域项目不需要引用您的持久性项目。
You'll want your Fluent config class in your persistence project with your
ClassMap
classes, not your domain models.Using your code sample, you'd want to
AddFromAssemblyOf
on yourMap
class and not yourModel
class. See:This way, your domain project doesn't need to reference your persistence project.