如何通过 FluentNHibernate 配置避免将域层暴露给基础设施层?
我的 NHibernateUtil 类位于应用程序的基础设施层中,但是我遇到了这一行的问题:
...
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Computer>());
为了使其正常工作,我必须将域层暴露给基础设施层。由于映射(例如 ComputerMapping),域层还可以访问基础设施层,这会导致循环依赖。
如何告诉配置 FluentNHibernate 访问正确的程序集而不给予基础设施层访问域层的权限?
I have my NHibernateUtil class in the infrastructure layer of my application, however I arrive at a problem with this line:
...
.Mappings(m => m.FluentMappings.AddFromAssemblyOf<Computer>());
For this to work I have to expose the domain layer to the infrastructure layer. The domain layer also has access to the infrastructure layer due to the mappings (e.g. ComputerMapping) and this causes a circular dependency.
How does one tell configure FluentNHibernate to access the correct assembly without giving the infrastructure layer access to the domain layer?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不明白为什么您需要引用域层内的基础设施层。通常,您应该这样构造它:
包含域类和定义这些类上的操作的接口的域
引用域层的数据访问层和实现给定提供程序的接口(例如 SQL 和 NHibernate)。在这里,您放置了流畅的 nhibernate 映射类和配置,允许您构造一个用于接口实现的
ISessionFactory
。您只需公开这些接口的实现,其他一切都是私有的。主要应用程序引用前两层。在这里,您可以使用对象容器来选择域接口的正确实现。
如果稍后您决定使用其他技术来访问数据(例如实体框架),您需要编写另一个具有不同域接口实现的数据访问层,并通过仅修改对象容器(DI ) 代码。
I don't understand why you need to reference the infrastructure layer inside your domain layer. Normally you should structure it like this:
Domain containing domain classes and interfaces which define operations on these classes
Data access layer referencing the domain layer and implementing the interfaces for a given provider (for example SQL qith NHibernate). Here you put the fluent nhibernate mapping classes and the configuration allowing you to construct an
ISessionFactory
used in the implementation of the interfaces. You only expose the implementation of these interfaces, everything else is private.Main application referencing the previous two layers. Here you might use an object container to select the proper implementation of the domain interfaces.
If later you decide to use some other technology to access your data such as Entity Framework for example you need to write another data access layer with a different implementation of the domain interfaces and plug it in the main application by modifying only the object container (DI) code.