skip to content

Adam Tibi on Software Engineering & Architecture

Linkedin Twitter feed logo
  • 22 June 2013

    Implementing a CQRS-based Architecture with MVC and Document DB

    MVC MongoDB Ninject CQRS

    This is a sample implementation of ASP.NET MVC4, MongoDB and Ninject to act as a starting template if you are going to use these technologies in your project with a CQRS pattern.

    Audience

    If most of these terms look unfamiliar then this post is probably not for you: CQRS, Repository, Aggregate (of DDD), NuGet, Unit Testing, Dependency Injection, Document DB. Due to the scope of this post, I won’t be able to go in details in any of these topics as this is a direct implementation.

    Greg Young did a few paragraphs intro on CQRS here: CQRS, Task Based UIs, Event Sourcing agh, if you want a simple intro I recommend at least reading the first half of Greg’s post (before the Event Sourcing).

    Scope and Definition

    In this post, I mean the plain-CQRS pattern and not the whole patterns that are associated with CQRS. Plain CQRS opens the door for other patterns such as Event Sourcing and ES is usually associated with CQRS. This is the plain CQRS with no other associated pattern.

    Read the rest of this entry »

  • 18 June 2013

    Five Essential Front-End Tools That Should be Used with Modern MVC Projects

    Microsoft is doing a good job in shipping standard front-end libraries with Visual Studio 2012 “ASP.NET MVC 4 Web Application” and “ASP.NET Web Forms Application” templates, they are raising the bar for the .NET web developers.

    The VS template is a good starting base, however, I have been adding the libraries of this post to every new web project, they act as a completion to the ones shipped with VS and I wanted to share them with you.

    Read the rest of this entry »

  • 17 June 2013

    A Call To Drop “The Open Closed Principle” From The SOLID Design Principles

    SLID

    The OCP or “The Open Closed Principle” is the popular “O” from the SOLID principles of Object-Oriented Design.

    As an architect consultant working in London, I get a question about SOLID, every other interview. As usually the interview is about an hour, I answer the question by an out-of-the-textbook type of answer, otherwise, the interview will span for hours. I keep my opinions for myself and I am a happier person :)

    Read the rest of this entry »

  • 16 June 2013

    You should unit test your controller, NOT!

    Unit Testing MVC

    Unit testing per se is a controversial topic, what you should unit test is another controversial topic. The topic of this post started by a short conversation during a .NET London Group meeting back in 2010, I thought about it and then gave it more thoughts, I started using it in my projects, then now I have enough confidence to share my thoughts. Here is my opinion, if you agree or disagree, then please do comment.

    Read the rest of this entry »

  • 16 June 2013

    Three Steps to Get Fat-Razor MVC Views on Diet

    Fat Razor in MVC

    Let me first define the terms that I will be referring to:

    Presentation Code: Is the minimal code in a view that is necessary to display visual elements, but does not take any business decision. This is a fictional simple example:

        // Business Logic Code. This code understands how the business works
        // (don't do this)
        @if (Model.IsMonthly && !Model.IsPaid && Model.Payment >= 12 && ...)
        {
    	    <p>Some warning message</p>
        }
        
        // Presentation Code. This code is only concerned with whether to
        // show or hide a UI element.
        @if (Model.ShouldWarn)
        {
    	    <p>Some warning message</p>
        }
    

    Fat-Razor: I’ve coined this term to define ASP.NET Razor views with a lot of Razor/C# code that is not presentation code. This is about the Razor/C# code specifically and not about HTML/CSS/JS.

    Model: This is an overloaded term. However, in this context, it is an object of data representation such as a record in the database.

    Viewmodel: They are data transfer objects that are meant to be view-specific and to carry exactly what the view needs, no less and no more. Generally, viewmodels are non-reusable and each vm is meant to to be tightly coupled to one view, however, there are exceptions depending on what you are doing.

    To give you a flavour of a model and a viewmodel:

    // An example of a model
    public class Person
    {
        public Guid PersonId { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        public short YearOfBirth { get; set; }
        public DateTime LastAuth { get; set; }
        // This might represent a one-to-many db relationship
        public Order[] Orders { get; set; }
    }
    
    // An example of a viewmodel
    public class ProfileViewModel
    {
        // Doesn't necessarily need an id
    
        // Combined first and last name
        public string Name { get; set; }
        // Calculated from YearOfBirth
        public short Age { get; set; }
        // E.g. "One day ago" and constructed from LastAuth
        public string LastSeen { get; set; }
        // Calculated by projections on Orders
        public short NumberOfAllOrders { get; set; }
        public short NumberOfUndeliveredOrders { get; set; }
    }
    

    Read the rest of this entry »