洋葱架构:工厂实现应该放在哪里?
我要构建新的“企业解决方案”,
所以我决定使用“洋葱架构”,因为我想要尽可能灵活的架构。
但我对“依赖解析”问题很陌生。
据我了解,我应该将工厂“实现”放在该层中,并且该层引用所有其他层。
然后我想知道当 DependencyResolution 中的 FactoryImplementation 层和 UI 层不这样做时,如何在“UI 层”中创建 IFactory 的新实例参考“DependencyResolution Layer”
编辑::
感谢埃里克先生
,但在我看到其中许多链接后,当我想“注册”实现时,我仍然遇到问题他们的“接口”,因为我无法在 UI 项目中执行类似的操作:
kernel.Bind<ITaxCalculator>()
.To<TaxCalculator>()
.WithConstructorArgument("rate", .2M);
因为 UI 项目无法访问 TaxCalculator
“实现”。
I'm coming to build new "Enterprise solution"
So i decided to use "Onion Architecture" because i wanna as much as flexible architecture.
But I'm new to "Dependency Resolution" concern.
As I understand I should put Factories "Implementations" in this Layer and this layer has references to all other layers.
Then I wanna know how to make new instance of IFactory in the "UI Layer" when the FactoryImplementation in DependencyResolution Layer and UI Layer don't have reference to "DependencyResolution Layer"
Edit::
Thanks to Mr. Erik
But after I saw many of these links I still have problem when i want to "Register" Implementations to their "Interfaces" because I can't do something like this in UI Project:
kernel.Bind<ITaxCalculator>()
.To<TaxCalculator>()
.WithConstructorArgument("rate", .2M);
Because UI Project can't access TaxCalculator
"Implementation".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最好的解决方案是使用依赖容器(又名 IOC 容器)来解析您的引用,例如 Castle Windsor 或 Unity(如果您使用 .NET)。它们使您能够配置依赖项解析,而无需引用 UI 层中的实际实现。
编辑:一些链接:
I think the best solution would be to use a Dependency Container (aka IOC container) to resolve your references, such as Castle Windsor or Unity if you're on .NET. They make you able to configure up the dependency resolution without references to the actual implementations in the UI layer.
EDIT: Some links: