Assembly references across projects - need for more than one Entity Framework reference?

655 views Asked by At

For the sake of the question, I have a project structured as follows, where each layer maps to a project in my visual studio solution:

  • Presentation Layer
  • Business Logic Layer
  • Data Layer (working with Entity Framework)

I have repository classes defined in my Data Layer. Upon instancing them in the BL layer, I get an error stating that a reference to the entity framework assembly is missing. I add a reference to the same entity framework dll that is being used in my DL and it works.

My question is: why is it not sufficient to have the BL reference the DL, why do I still need to add an "additional" reference to EF in the BL ? I obviously do not want to control more than one EF version in my solution.

I would think my DL is an "atomic" unit, all its objects are self contained and need nothing else to function properly. Why then upon instancing classes defined in the DL would I still need to add a EF reference, what with the DL's own EF reference ?

1

There are 1 answers

3
Rob Tillie On BEST ANSWER

This is indeed how the build engine MSBuild works. Visual Studio used to not complain about indirect references, only to found out at the TFS build server that it broke. As to why they build this the way they did, I do not have an answer.

I do have an easy fix: Use solution-level NuGet packages. You add the Entity Framework package to the solution as a NuGet package, and you check all the projects that should have this reference. This way also prevents multiple different versions.

For a detailed explanation, you can read this article.