NotoriousModules 1.0.0

dotnet add package NotoriousModules --version 1.0.0
                    
NuGet\Install-Package NotoriousModules -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="NotoriousModules" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NotoriousModules" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="NotoriousModules" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add NotoriousModules --version 1.0.0
                    
#r "nuget: NotoriousModules, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package NotoriousModules@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=NotoriousModules&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=NotoriousModules&version=1.0.0
                    
Install as a Cake Tool

Notorious Modules provide a simple way to separate monolith into standalone modules.

Summary

Support

  • Net6+

Features

  • Modules separation
  • Automatic injection
  • Global endpoints configuration
  • Easy modular monolith architecture
  • Based on net minimal apis

Motivation

The goal is to provide a way to separate applications into modules that can be moved at anytime without any pain. Based on Module monolith architecture.

Getting Started

First, install NuGet. Then, install NotoriousTest from the package manager console:

PM> Install-Package NotoriousModules

Or from the .NET CLI as:

dotnet add package NotoriousModules

Modules

What is a module ?

A module can be seen as an independent components with well-defined functionnal boundaries. It group together related functionnalities.

For example, in a basic e-commerce applications, we could have a modules for invoices functionnalities, orders, users, and cart.

img

How to implement modules

Notorious Modules provide a base class for modules :

public class ExampleModule : NotoriousModules.Modules
{
    public override string ModuleName => "Example";

    public ExampleModule() : base()
    {
    }

    protected override void ConfigureModuleEndpoints(RouteGroupBuilder routeGroupBuilder)
    {
        base.ConfigureModuleEndpoints(routeGroupBuilder);

		// Here you can configure your endpoints
		AddPostEndpoint("orders", async ([FromServices] GetOrdersFeature feature, [FromBody] GetOrdersParams @params) =>
		{
			return await feature.Handle(@params);
		});

    }

    protected override void ConfigureDependencyInjection(IServiceCollection services, IConfiguration configuration)
    {
        base.ConfigureDependencyInjection(services, configuration);
		// Here you can configure your dependency injection.
    }

    protected override void ConfigureApp(WebApplication app)
    {
		base.ConfigureApp(app);
		// Here you can configure your middlewares
    }

	protected override void ConfigureEachEndpoint(IEndpointConventionBuilder routeHandlerBuilder)
	{
		base.ConfigureEachEndpoint(routeHandlerBuilder);

		// Here you can configure every endpoint.
		// For example, lets configure OpenApi :
		routeHandlerBuilder
			.WithTags(ModuleName)
			.WithOpenApi();
	}
}

Module provide several method that u could override.

Use ConfigureModuleEndpoints with AddEndpoint, AddPostEndpoint, AddGetEndpoint, AddPutEndpoint, AddDeleteEndpoint or AddPatchEndpoint to configure your minimal apis.

Use ConfigureDependencyInjection to configure the application injection container.

Use ConfigureApp to configure modules middlewares.

Use ConfigureEachEndpoint to configure every endpoint of a module.

Configure application to use modules

In your Program.cs, you will need to register every modules :

// IServiceCollection AddModules(this IServiceCollection services, IConfiguration configuration, params Assembly[] assemblies)
builder.Services.AddModules(builder.Configuration, Orders.AssemblyMarker.Get(), Cart.AssemblyMarker.Get());

Pass-in assemblies that contains modules, they will be automatically retrieved and used.

:information: You can't add constructor parameters to modules.

Then, you just need to use theses modules :

var app = builder.Build();
app.UseModules();

And that's it, now u can create an infinite number of modules or extend module to create your own base modules.

For example, here's one module that integrate Swagger UI :

public abstract class OpenApiModule : Module
{
    public OpenApiModule() : base()
    {
    }


    protected override void ConfigureEachEndpoint(IEndpointConventionBuilder routeHandlerBuilder)
    {
        base.ConfigureEachEndpoint(routeHandlerBuilder);

        routeHandlerBuilder
            .WithTags(ModuleName)
            .WithOpenApi();
    }
}

public class ExampleModule : NotoriousModules.OpenApiModule
{
    public override string ModuleName => "Example";

    public ExampleModule() : base()
    {
    }

    ...
}
Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0.0 147 6/6/2024