开发者

Onion Architecture and Registering Dependencies in DI Container

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 i开发者_运维知识库t register IDatabaseService to resolve to DALDatabaseService?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜