Send mail to the author(s) E-mail

# Friday, 24 January 2014

There are going to be in depth notes here from this article.  Please consider buying the whole pdf  from him (as I have) as it

These are purely my notes Imar’s article.

My goals are:

  • Understand this architecture as it “can be used to build real-world, large scale web applications.”
  • Build up from scratch his sample
  • Build out my own Winter Project app with the concepts I like from here
  • Pragmatic
  • Simple

Why Use N-Layers

  • Testability
  • Separation – make it easier to find where things are in large projects eg dataaccess, business logic, UI
  • Reuse – eg a console app can use all the goodness of the main MVC app


Previous Versions

  • BLL/DAL – lots of pass through code
  • DAL tight coupling making hard to test
  • SP’s hard to maintain and test
  • Validation was custom – now have better ways

Sidenote: PDF reader being horrible.. trying:

Starting from Scratch

Updating all packages

Also have enabled NuGet Package Restore.

My DLayer version.

Put into source control – am using github.

| | # 
# Wednesday, 11 December 2013

Want to display the list of Departments on the home page:


// Only want HomeController to know about IDepartmentDataSource and not a concreate implementation
        //private IDepartmentDataSource _db = new ApplicationDbContext();

        // A private field.
        private IDepartmentDataSource _db;

        // Poor mans DI
        public HomeController() : this(new ApplicationDbContext())

        public HomeController(IDepartmentDataSource db)
            _db = db;

Use IoC – Ninject, Unity, StructureMap


StructureMap plugs into the MVC Runtime. so we don’t need poor mans DI.

namespace eManager.Web.DependencyResolution {
    public static class IoC {
        public static IContainer Initialize() {
            ObjectFactory.Initialize(x =>
                            x.Scan(scan =>
                            // When you see something that needs IDep... then the concrete type to use is ApplicationDbContext
                            // and scope to a particular Http request
            return ObjectFactory.Container;


Right click inside the controller..

public ActionResult Index()
            var allDepartments = _db.Departments;

            return View(allDepartments);


Then we rewrote the scaffold like this:

@model IEnumerable<eManager.Domain.Department>

    ViewBag.Title = "All Departments";


    @foreach (var department in Model)
        @*<a href="/department/detail/5"></a>*@
| | #