Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>If I wasn't using an DI container, I wouldn't have to reference EntityFramework library in my MVC3 app</p> </blockquote> <p>Even when using a DI container, you don't have to let your MVC3 project reference EF, but you (implicitly) choose to do this by implementing the <a href="https://freecontent.manning.com/dependency-injection-in-net-2nd-edition-understanding-the-composition-root/" rel="nofollow noreferrer">Composition Root</a> (the startup path where you compose your object graphs) inside your MVC3 project. If you are very strict about protecting your architectural boundaries using assemblies, you can either move your Composition Root or your (MVC) presentation stuff to a class library.</p> <p>In the first option, you let your MVC3 project reference this separate 'bootstrapper' assembly, and it will reference all other assemblies in your solution plus reference your DI container library. The problem with this is that this bootstrapper project can't reference types located in the MVC3 project (because it will cause a cyclic assembly dependency). These types have to be moved to the bootstrapper project (that possibly needs to reference System.Web.Mvc), or you need to keep a small part of the container configuration inside your MVC3 app. Also note that your MVC project still references all other assemblies indirectly through the new bootstrapper assembly, because assembly dependencies are transitive.</p> <p>Although placing the Composition Root in a separate assembly is a valid thing to do, most DI purist (including me) usually only move the composition root to a class library when there are multiple end applications (i.e. a web app + web service + windows service) that use the same business layer. When I have a single application I keep the Composition Root inside my end application.</p> <p>The second option is to move all MVC related classes (views, controllers, etc) from the startup project to a class library. This allows this new presentation layer assembly to stay disconnected from the rest of the application. Your web application project itself will become a very thin shell with a the required startup logic. The web application project will be the Composition Root that references all other assemblies.</p> <p>Extracting the presentation logic to a class library can complicate things when working with MVC. It will be harder to wire everything up, since controllers and views, images, css files, etc. are not in the startup project. This is probably doable but will take more time to set up.</p> <p>Both options have their downsides and that's why I generally advice to just keep the Composition Root in the web project. Many developers don’t want their MVC assembly to depend on the DAL assembly, but that's not really a problem. Don't forget that assemblies are a <em>deployment</em> artifact; you split code into multiple assemblies to allow code to be deployed separately. An architectural layer on the other hand is a <em>logical</em> artifact. It's very well possible (and common) to have multiple layers in the same assembly.</p> <p>In this case we'll end up having the Composition Root (layer) and the Presentation Layer in the same web application project (thus in the same assembly). And even though that assembly references the assembly containing the DAL, the Presentation <em>Layer</em> still does not reference the Data Access <em>Layer</em>. This is a big distinction.</p> <p>Of course, when we do this, we lose the ability for the compiler to check this architectural rule at compile time, but this shouldn't be a problem. Most architectural rules actually can't be checked by the compiler and there's always something like common sense. And if there's no common sense in your team, you can always use code reviews (which every team should IMO always do btw). You can also use a tool such as NDepend (which is commercial), which helps you verifying your architectural rules. When you integrate NDepend with your build process, it can warn you when somebody checked code in that violates such architectural rule.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload