Ardalis.Modulith 1.1.2

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet new install Ardalis.Modulith::1.1.2                
This package contains a .NET Template Package you can call from the shell/command line.

CI NuGet Version

Modulith is a dotnet new template suite for Modular Monoliths. It streamlines the creation of new .Net solutions and the addition of modules to existing ones.

But, what is a Modular Monolith? Glad you asked. It is a software architecture style to build maintainable applications as a single unit, but in nicely separated modules (Modu-lith, pun intended 🙃). More about Modular Monoliths.

🏁 Start here

Install by running:
dotnet new install Ardalis.Modulith
Create a new solution:
dotnet new modulith -n eShop --with-module Payments 

eShop is your solution name, and Payments is the first module name (defaults to FirstModule if not specified).

Create a new module
cd eShop
dotnet new modulith-proj --add-module Shipments --to eShop

⚠️ cd into the solution folder to add the module inside the solution.

Shipments is the name of your new module. This will create a new module folder with the same three projects as in Users/.

Add a reference to the new module

Run:

dotnet add eShop.Web/eShop.Web.csproj reference Shipment/eShop.Shipment/eShop.Shipment.csproj

🏛️ Solution directory structure

The previous command creates the following project structure:

  • eShop
    • Users/ 👈 Your first module
    • eShop.Web/ 👈 Your entry point

Inside Payments, you will find the project folders:

  • eShop.Payments/ 👈 Your project code goes here
  • eShop.Payments.Contracts/ 👈 Public contracts other modules can depend on
  • eShop.Payments.Tests/ 👈 Your module tests

Project dependencies

Since this is a Modular Monolith, there are a few rules that are enforced to guarantee the modularity:

  • Every type in eShop.Payments/ is internal
  • This 👆 is enforced by an archUnit test in eShop.Payments.Tests/
  • The only exception to the last two rules is the static class that configures the services for the module: UsersModule...Extensions.cs
  • .Contracts/ and .Tets/ projects depend on eShop.Payments/. The opposite is not possible. This is by design.

* You can always change these rules after you have created the solution to suit your needs. But be mindful of why you are changing the rules. For example, it is ok to add an additional public extensions class to configure the application pipeline, while adding a public contract to eShop.Payments/ is not. We have a project for those.

Adding a reference automatically to new modules

We support this, but the .Net SDK does not yet. There is an active PR at dotnet/sdk #40133. Give it a vote if you'd like this feature:

⚠️ cd into the solution folder. I.e. eShop/, then run:

dotnet new modulith-proj --ModuleName Shipments --existingProject eShop.Web/eShop.Web.csproj

Here Shipments is the name of your new module, and eShop.Web/eShop.Web.csproj is the path to your web entry project. If you changed this, make sure you update it to the new path and that is relative to the solution folder.

📊 About Modular Monoliths

A Modular Monolithic app benefits from the simple deployment of a monolith and the separation of concerns that microservices offer. While avoiding the complexities and maitainability issues they can introduce. When you are ready and if you need it, you can split a module as a microservice. Best of both worlds 🌎

This is not a new concept. Martin Fowler explains it here, and Ardalis teaches it here.

The templates in this project follow the solution structure as taught by Ardalis in his course Modular Monoliths in DotNet.

🛃 Custom templates

No template fits all needs. If you weant to customize the template you can change it in the working/content directory and running:

⚠️ Make sure to uninstall the original template

dotnet new install .

🗑️ Uninstall Modulith

dotnet new uninstall Ardalis.Modulith
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.3-alpha.0.1 52 10/4/2024
1.1.2 237 10/4/2024
1.1.2-alpha.0.3 45 10/4/2024
1.1.2-alpha.0.2 50 10/4/2024
1.1.2-alpha.0.1 44 10/4/2024
1.1.1 78 10/4/2024
1.1.1-alpha.0.1 51 10/3/2024
1.1.0 116 9/30/2024
1.0.1-alpha.0.1 41 9/30/2024
1.0.0 116 9/22/2024
0.0.9 113 9/19/2024
0.0.9-alpha.0.1 53 9/19/2024
0.0.8 92 9/19/2024
0.0.8-alpha.0.2 43 9/19/2024
0.0.8-alpha.0.1 48 9/19/2024
0.0.7 113 9/12/2024
0.0.7-alpha.0.3 48 9/12/2024
0.0.7-alpha.0.2 51 9/12/2024
0.0.7-alpha.0.1 49 9/12/2024
0.0.6 94 9/12/2024
0.0.6-alpha.0.6 52 9/12/2024
0.0.6-alpha.0.4 52 9/12/2024
0.0.6-alpha.0.2 60 9/9/2024
0.0.6-alpha.0.1 49 8/27/2024
0.0.5 159 8/21/2024
0.0.5-alpha.0.9 86 8/17/2024
0.0.5-alpha.0.8 79 7/11/2024
0.0.5-alpha.0.7 62 7/8/2024