C# 和 Visual Studio 2005 中的程序集之间的循环引用(再次...)
请首先阅读以下线程:
程序集之间的循环引用C# 和 Visual Studio 2005
实现接口解决了我的问题,但没有实现我的目标。
我的目标是仅使用 UI 层/组件中的 BO 层/组件。 这样我就可以保持清晰的层与层参考。
因为我不想在 UI 层/程序集中添加 BO 层/程序集和 ORMapper 层/程序集的引用。
我只想在 UI 层/程序集中使用 BO 层/程序集。
同时有人建议我,这只能通过反射来实现,而不是 DI。 真的吗?
Please first read the following thread:
Circular reference between Assemblies in C# and Visual Studio 2005
Implementing interfaces is solving my problem but not fulfilling my target.
My target is to work only with BO-layer/assembly from the UI layer/Assembly. So that I can maintain a clean layer-to-layer reference.
Coz I don't want a reference to be added both for BO-layer/assembly and ORMapper-layer/assembly in the UI-layer/assembly.
I only want to work with BO-layer/assembly from within UI-layer/assembly.
Meanwhile someone suggested me that, it can only be possible with using Reflection, not DI. Is that true?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您确实坚持将 ORM 层隐藏在 BO 层后面,那么依赖注入仍然可以帮助您。 请注意,您将无法摆脱从 UI 线程引用 DI 库的情况,因为那时您的业务对象将来自那里。
方法:
User
对象的方法User
对象提供一个构造函数,该构造函数采用人口接口的实例来加载数据 然后当您需要一个
User
对象,您要求 DI 库创建它,DI 库将构造User
并为其提供对 ORM 实现的引用。 您还必须将一些属性注入到 DI 调用中,以便“用户名”和“密码”能够用值完全填充它。请注意,这并不是 DI 的发明目的……应用程序代码实际上应该直接处理 ORM 来创建/读取/更新/删除业务对象。
If you really insist on hiding the ORM layer behind your BO layer, then Dependency Injection should still be able to help you out. Note that you will not be able to get away from referencing the DI library from your UI thread though, because that'll be where your business objects will come from then.
Approach:
User
objectsUser
object a constructor that takes an instance of the population interface to load data fromThen when you need a
User
object, you ask the DI library to create it, and the DI library will construct theUser
and give it a reference to the ORM implementation. You'll have to inject some properties into the DI call as well for the 'username' and 'password' to be able to fully populate it with values.Note that this is not exactly what DI was invented for... application code is really supposed to deal with ORM directly to create/read/update/delete business objects.