Onion Architecture and Registering Dependencies in DI Container

我是研究僧i 提交于 2019-12-05 04:35:19

问题


I have been reading up on the Onion architecture, and I have what I think is a simple question about how assembly dependencies should be arranged for a DI container to be able to wire everything up.

Assume a very simple solution that has the following structure:

UI => BL <= DAL

So the UI and DAL reference the BL, but have no knowledge of each other.

Also assume the BL has an interface called IDatabaseService, which is implemented in the DAL by DALDatabaseService.

The container would (presumably) be configured in the UI's entry point. Since the UI has no knowledge of the DAL, how can it register IDatabaseService to resolve to DALDatabaseService?


回答1:


Most of the time this is done by making the container aware of the DAL (via configuration) and sticking the DAL's assemblies in the same directory as the UI or other well-known location (the GAC, etc). In Spring.NET you'd add the DAL's types in the spring configuration file. In Castle Windsor, you can include a class implementing IWindsorInstaller in each DLL that has types to be registered in the IoC container, and in the UI tell the container to go find all components in a certain directory.



来源:https://stackoverflow.com/questions/7787355/onion-architecture-and-registering-dependencies-in-di-container

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