Teach Yourself DDD in 5 Minutes

DZone 's Guide to

Teach Yourself DDD in 5 Minutes

Make yourself the envy of your department with this open source tool that makes quick work of DDD.

· Open Source Zone ·
Free Resource

DDD or "Domain-Driven Design" is arguably the holy grail of software architecture. Martin Fowler has written dozens of books covering the subject, and many developers have spent decades of their lives trying to catch up with his ideas, often unsuccessfully, I might add. For those able to implement a DDD architecture, the salaries ranges from $100,000 per year and upwards, often into the millions.

I have created 450 lines of open source code, which not only allows you to learn this skill, but also provides an excellent starting point to apply it into your own projects. In such a way, it arguably becomes the shortcut through the abyss to that green and cozy place where everything evolves around your domain types and brilliant architecture is a commodity. As an added bonus, I've based my entire methodology upon copy and paste.

Image title

Magic is a starter kit for your own ASP.NET Core web APIs, allowing you to start out running, with a perfectly-architected DDD architecture, solving 80% of your problem, while still allowing you to easily extend it where ever needed. If you're a new developer, believe me, it'll make the senior guru developers around you jealous.

It's all based upon generics from C#, and intelligent use of polymorphism, allowing you to literally create your web APIs, almost completely without having to code. It's also stuffed with all the greatest acronyms and words our industry has seen the last decade, such as Dependency Injection, IoC, modular design,  and service-based architecture. You name it, it's got it! In fact, just listing all its implemented acronyms would probably require an entire dictionary, so I'll avoid doing it.

To put things into perspective, let me illustrate a TODO controller endpoint with Magic that has 6 HTTP REST endpoints. Notice, that this is its entire code.

public class TodoController : CrudController<www.Todo, db.Todo>
    public TodoController(IAdapter adapter, ITodoService service)
        : base(adapter, service)
    { }

Pretty nifty, huh ...?

The whole idea is build around DRY, meaning "Don't Repeat Yourself," and CRUD principles. You see, both HTTP REST and SQL are conceptually based around CRUD, which stands for Create, Read, Update and Delete. That tiny little base class called "CrudController" (123 lines of code) from above just so happens to be able to go through the mechanisms of C# generics and solve that entire domain problem for you, using Fluent nHibernate and Domain Driven Design principles, resulting in that 123 lines of code, having already done 80% of your job. The result is that before you have created one single line of code yourself, you already have all the CRUD operations on your domain types, without as much as a single line of code added by you to your class. Let me show you the Swagger UI documentation for this class to illustrate my point.

Image title

Notice, the above (empty) class produced all 6 HTTP REST endpoints above, and we got documentation for free. We even have our own service interface, service implementation, domain model types, view model types, and the whole shebang!

Go get your 15 minutes of fame, and download your own personal Magic wand today.

Additionally, here's a YouTube video at the project website, illustrating how to get started with Magic. And if you're curious to look behind the hood to understand what goes on in the background, the project is roughly 400 lines of code in total, and can easily be understood within 20 minutes for a seasoned software developer.

architecture, asp.net core, c#, ddd, open source

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}