1

I am reading through 'Dependency Injection in .Net' and would like to being implementing some of the ideas presented. To be absolutely upfront, I would like to attempt a 'Poor Mans DI'/No DI Container -- manually managing Dependencies -- to better understand the concepts before jumping into a DI Container.

There is an example illustrated in Chapter 2 that demonstrates a Composition Root and creating the dependencies (and constructor injection). The basic idea was similar to this:

Web Project (has CompositionRoot.cs) --> Domain Project <-- DataAccess Project

The Composition root creates a DataAccess instance and passes it to the constructor of the Domain project's classes -- all of the dependencies are read from the web.config.

I am completely on board with the above idea and agree the Web Project shouldn't reference the DataAccess project. My understanding at this point is that the Web Project really does need a reference to the DataAccess project in order to create an instance via Reflection.

My questions:

  1. My understanding would be that I would need to copy over the DataAccess.dll to the Web Project's Bin folder for everything to build. This seems very labor intensive so I would be interested in setting Visual Studio to do this for me? This was all I found thus far.

  2. How does a DI Container resolve what I have described? ** I haven't looked into any containers yet so I am unaware if they would require a hard reference to the dependency project.

Community
  • 1
  • 1
Daniel
  • 191
  • 2
  • 8

1 Answers1

0

My understanding would be that I would need to copy over the DataAccess.dll to the Web Project's Bin folder for everything to build.

Since you have a separate DataAccess.dll, then yes.

I would be interested in setting Visual Studio to do this for me

You can use pre build events to do so (in the Build tab of the project property pages).

Consider that you may not need to if you still do DI but in the same project. Projects should be deployment units, when you physically need to deploy classes separately. Use namespaces/directories for logical separation and you will not have this issue.

How does a DI Container resolve what I have described?

You tell it. Either explicitly when configuring it, or using conventions.

Oded
  • 489,969
  • 99
  • 883
  • 1,009