Skip to content

Infinity Toolkit is a collection of useful utilities simplifying development of modular monoliths.

License

Notifications You must be signed in to change notification settings

penyland/infinity-tomahawk

Repository files navigation

infinity-toolkit

Infinity Toolkit is a collection of useful utilities simplifying development of modular monoliths and applications using vertical slice architecture.

Features

  • Feature modules - Let's you automatically register dependencies and endpoints in modules which simplifies development when you are working in feature slices.
  • Mediator - A bare bones mediator test. (WIP)
  • Logging formatter - logging formatter with a Visual Studio Code inspired theme and Serilog like formatting

Feature modules

Infinity.Toolkit.FeatureModules is a library that simplifies development applications where you want to split functionality in different modules. It is especially useful when you are working with vertical slices in a modular monolith or application. However though, the library can be used in any type of application. It let's you automatically register dependencies and endpoints in modules which simplifies development when you are working in feature slices.

Quick Start

To get started with Feature Modules there are two options:

  1. Look at the sample project in the repository. The sample project found here FeatureModulesSample is a simple web api with two feature modules.
  2. Create a new project and integrate the library.

Let's look create a new project and integrate the library.

  1. Create a new web api project using the dotnet cli.
dotnet new webapi -n MyWebApi
  1. Add the Infinity.Toolkit.FeatureModules package to the project.
dotnet add package Infinity.Toolkit
  1. In Program.cs, add the following code:
using Infinity.Toolkit.FeatureModules;

var builder = WebApplication.CreateBuilder(args);
builder.AddFeatureModules();

var app = builder.Build();

app.MapFeatureModules();
app.Run();

This will add all feature modules added to the project and add the modules services to the application. The MapFeatureModules method will map all endpoints to the application.

  1. Run the application and make sure that it is working. The application should return a 404 error since there are no endpoints mapped to the application.

Create a feature module

  1. Create a new class called WeatherModule.cs in the root of the project. Make sure to remove the endpoint that was created by the template. Add the following code to the WeatherModule.cs file.
internal class WeatherModule : WebFeatureModule
{
    public override IModuleInfo? ModuleInfo { get; } = new FeatureModuleInfo("WeatherModule", "1.0.0");

    public override void MapEndpoints(IEndpointRouteBuilder builder)
    {

        var summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        builder.MapGet("/weatherforecast", () =>
        {
            var forecast =  Enumerable.Range(1, 5).Select(index =>
            new WeatherForecast
            (
                DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                Random.Shared.Next(-20, 55),
                summaries[Random.Shared.Next(summaries.Length)]
            )).ToArray();

            return forecast;
        })
        .WithName("GetWeatherForecast")
        .WithOpenApi();
    }
}

internal record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
{
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
  1. Run the application and navigate to the /weatherforecast endpoint. You should see the weather forecast.

Feature modules in a class library

The sample project also refers to a class library with another feature module. When you add the class library to the project, the feature module will be automatically registered and the endpoints will be mapped to the application.

Types of feature modules

There are two types of feature modules:

  1. FeatureModule
  2. WebFeatureModule

The difference is that the WebFeatureModule has access to the IEndpointRouteBuilder which allows you to map endpoints to the application. To create a web feature module, you need to create a class that inherits from WebFeatureModule or implements IWebFeatureModule.

Mediator

A simple mediator implementation that can be used to send messages between different parts of the application. This is a work in progress and will be updated with more features and examples. Currently this is a test using TPL Dataflow.

Logging formatter

A logging formatter that formats log messages with a Visual Studio Code inspired theme and Serilog like formatting.

Contributing

If you have any ideas, suggestions or issues, please create an issue or a pull request. Or reach out to me on BlueSky.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

Infinity Toolkit is a collection of useful utilities simplifying development of modular monoliths.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages