A11d.Module
0.1.0
See the version list below for details.
dotnet add package A11d.Module --version 0.1.0
NuGet\Install-Package A11d.Module -Version 0.1.0
<PackageReference Include="A11d.Module" Version="0.1.0" />
<PackageVersion Include="A11d.Module" Version="0.1.0" />
<PackageReference Include="A11d.Module" />
paket add A11d.Module --version 0.1.0
#r "nuget: A11d.Module, 0.1.0"
#:package A11d.Module@0.1.0
#addin nuget:?package=A11d.Module&version=0.1.0
#tool nuget:?package=A11d.Module&version=0.1.0
Modules
The goal of this package is to provide a way to organize your application into modules to improve cohesion in your codebase. Each module can configure the services in the installation phase, configure the application and define endpoints in the build phase.
Installation
You can install this package using the following command:
dotnet add package A11d.Modules
API
Modules
The Module class is the base class for all modules. It provides three virtual methods that you can override to add services, configure the application, and define endpoints:
ConfigureServicesto configure your application using theIServiceCollectionparameter in the installation phase. Calling base is not needed.ConfigureApplicationto configure your application using theWebApplicationparameter in the build phase. Calling base is not needed.ConfigureEndpointsto define your application endpoints using theIEndpointRouteBuilderparameter in the build phase. Calling base is not needed.
Application Entry Point
In your program entry point, you have two extension methods to install and configure your modules:
Installto install your module using theWebApplicationBuilderparameter in the installation phase.Configureto configure your module using theWebApplicationparameter in the build phase.
Usage
First, activate the module in the entry point of your application:
// FILE: "./Program.cs"
WebApplication.CreateBuilder(args)
.Install<MyApplication>().Build()
.Configure<MyApplication>().Run();
// This is just a marker class to identify the assembly that contains the modules.
public class MyApplication { }
Then you can create modules to organize your application.
For example, consider a part of your application deals with Accounts and you want to organize it into a module. You can create AccountsModule:
// FILE "./Accounts/AccountsModule.cs"
namespace MyApplication.Accounts;
// Assuming this module has a DbContext, GetAccount, and AuthenticateAccount command classes.
public class AccountsModule : Module
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<AccountDbContext>();
services.AddTransient<GetAccount>();
services.AddTransient<AuthenticateAccount>();
}
public override void ConfigureApplication(WebApplication application)
{
application.UseAuthentication();
application.UseAuthorization();
}
public override void ConfigureEndpoints(IEndpointRouteBuilder endpoints)
{
endpoints.MapGet("/accounts/{id}", (GetAccount getAccount, Guid id) => getAccount.ExecuteAsync(id));
endpoints.MapPost("/accounts/authenticate", (AuthenticateAccount authenticateAccount, AuthenticateAccount.Request request) => authenticateAccount.ExecuteAsync(request));
}
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
-
net7.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.