Onion archicecture dependencies in the same layer: Infrastructure and Web communicating

只谈情不闲聊 提交于 2019-12-02 13:59:43

You are correct that you don't want Infrastructure to depend on UI(Web), but I break that rule sometimes.

I would think instead of IViewModelMapping, create IMapper with method Map(). Then, the interface can have implementations that might have to do with view model mapping, or maybe just regular mapping. Either way, that interface can be in Core because it is not semantically bound to any type of model.

Great graphic. I hope I answered the meat of your question. The overall philosophy of the Onion Architecture is to keep your business logic and model in the middle (Core) of your application and push your dependencies as far outward as possible.

Try to move Object Mapping into Web layer.

Your Web/UI layer can be dependent on Infrastructure layer. But it's not a good design to have dependency of Web on Infrastructure layer. Onion architecture says push your dependencies as far outward as possible.

You can create a "\Builder" folder in UI. Add one interface file in it,example.. IBuilder or IMapper and declare a method like ConvertToViewModel or CreateMapping in it. whatever you like.

*Builder **IBuilder.cs -declare a method here. **Builder.cs -- - Implement the method here,define mapping between a ViewModel and it's corresponding DomainModel( reference from core layer) and return appropriate ViewModel here.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!