Using smart modules in .NET 6 minimal API

Опубликовано: 01 Январь 1970
на канале: Codewrinkles
2,561
48

The minimal API in .NET 6 is great because it is less opinionated than the controller based approach and hence it gives us more freedom to organize our code differently. One approach that we think might be very useful is the module based approach. We can just organize our different features into self-contained modules (similar to Angular modules, for instance).

To achieve this there is a nice, small NuGet package called SmartModules. When using this package we can easily create module classes by implementing the IModule interface. The library will then automatically register all our endpoints in the different modules that we might have in an application.

In this video we showcase how to get started with SmartModules in .NET 6 minimal APIs, going through different concepts like modules, endpoint definitions and dependency injection.
#dotnet6 #aspnetcore #csharp

NuGet URL for SmartModules: https://www.nuget.org/packages/Codewr...
GitHub repo: https://github.com/danpdc/cwk.Minimal...

Here's also a more complex sample app, that features richer modules, with endpoint definitions and following a vertical slices architecture using MediatR: https://github.com/danpdc/ThoughtFul

Chapters
1. Intro: 00:00
2. Meet the SmartModules NuGet package: 01:50
3. Creating a first module: 03:30
4. Adding necessary services and automatic route registrations: 06:46
5. Splitting registrations in different endpoint definitions: 08:36
6. Dependency injection in smart modules: 15:00
7. Injecting scoped services in modules or endpoint definitions: 17:05