3

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?

Phil Sandler
  • 27,544
  • 21
  • 86
  • 147

1 Answers1

2

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.

Chris Shain
  • 50,833
  • 6
  • 93
  • 125
  • So in Spring, you would have to use XML configuration in order to wire things up? And in Windsor, based on the example above, the DAL would have an installer that would be discovered at runtime in the entry point of the UI (app.xaml, global.asax, etc.)? – Phil Sandler Oct 20 '11 at 03:30
  • That's correct. For spring.net: http://www.springframework.net/doc-latest/reference/html/objects.html#objects-factory-class. For Castle IoC (their documentation is a *mess*, but I actually prefer Castle): http://docs.castleproject.org/Windsor.Installers.ashx – Chris Shain Oct 20 '11 at 15:11
  • Interesting, and makes sense. After poking around online, I have seen articles that advocate having an assembly just for dependency resolution. I think this would allow for not having to reference Windsor (for example) from every project. – Phil Sandler Oct 20 '11 at 16:57
  • Yes, that's a totally feasible (and probably advisable) approach. – Chris Shain Oct 20 '11 at 17:07