A reference architecture (part 12)

..continued from part 11


In this series I explained an approach on how to set up a solution. Of course, as this is only a simple case, various aspects can be different in your case.

You probably will end up using other frameworks for dependency injection, logging and validation. You might choose to create a separate query service that uses its own data access component to query its dedicated read-only database with specialized views, or maybe use WCF data services for that matter. Or decide that commands should never return anything, and simplify the request dispatcher and expose a validation operation next to the execute operation to allow consumers to first validate commands before executing them. Or change the fault contract so that it contains technical as well as business and validation errors. You might extend the domain with domain events and use a service bus, or in real complex cases apply CQRS techniques and implement event sourcing.

In any case I think this is a nice basic design to start with!

Where is the source code?

You can download the source code for free here. The only thing I ask is: let me know what you think: suggestions, questions, fixes or any other feedback is most welcome!


9 thoughts on “A reference architecture (part 12)

  1. rob says:

    i not find the presentation layyer ?

    good works!!!

    • Ludwig Stuyck says:

      Hi, this series was about back end architecture. Presentation layer is just a layer on top that consumes the service layer.

      • rob says:

        ok but also the presentation layer and part of this architecture.
        would have ended in cycle is then complete.

        but still it is a beautiful and useful article

  2. I found your reference Architecture pretty compelling .. I had to download the source to understand the solution project references going on there…

    Perhaps it’s my misconception, but I was under the impression that the data access layer in the scope of your infastructure layer shouldn’t be referenced by the presentional layers/tiers nor service API’s like your WebHost web application.

    • Ludwig Stuyck says:

      You are right: if you are a purist, there should be no references to the data layer itself but to interfaces. However, as I took the pragmatic approach and accepted the fact that Entity Framework is a strong dependency that will never change, I referenced the data later directly. It made things a lot easier. Actually, in a later phase (after I wrote this series) I also removed the repository and unit of work pattern; because I found no real advantages in abstracting Entity Framework with something that is already built in anyway. So now I use Entity Framework directly from the commands and queries. Thanks for the comments.

      • yeah.. that seems to be the general consensus I’ve been reading from software designers, developers, and archtects who’ve used UnitOfWork with Entity Framework.. The only compelling point I’ve heard on keeping that abstraction was in the context of an EF1 migration project.

        That does bring up another question regarding project referencing libraries/packages, in particular EntityFramework.. is it safe to say it’s unnecessary to reference it in any layer other then the outter layer of this Onion Architecture (i.e. Infrastructure and Presentation).. excluding Service Hosting apps in the service layer… actually, it isn’t neccessary in the Infrastructure.Shared project in your source right?

        also, using a mock version of EF’s TextTemplating file.. I’ve moved my database-first models/entities into the domain.entities project (rather i templated it from there, and had it point to EDM file in the infrastructure layer).. but that couples my domain entities to existence of that file in the infastructure layer.. I see in your source you’re referencing FluentValidation..

        Would it be a better (and or even possible) to just add EntityFramework and a Entity Data Model into the domain.entities project.. and have it output just the classes.. and also keep the same EDM file in my infrastructure.dataaccees project and have it produce just the context?

  3. Alex says:

    This post series are amazing! I have learnt a lot. By far one of the best project examples to see how get a clean architecture. Thanks for your time to give us this explanation!

  4. David Cherian says:

    Hi Ludwig,
    Thanks a lot for this wonderful tutorial. Being a newbie to architecting, for completion of this article and to get to know the full cycle of the architecture, will it be possible for you to add the presentation layer proj as well (maybe an MVC 5 project).
    Anyway thanks a lot for this well explained tutorial.

  5. Anthony Benavente says:

    Hello, Ludwig.

    These posts where extremely informative and helpful. However, the link to the source code produces a 404 error. Is there another place I can find it?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s