Attributes for services
You put [SingletonService], [ScopedService], or [TransientService] on a class. The generator writes one registration call for each service.
DependencyModules is a source generator for Microsoft.Extensions.DependencyInjection. You put attributes on your classes. The generator writes the registrations when you compile.
using DependencyModules.Runtime.Attributes;
namespace Shop;
public interface IPriceCalculator
{
decimal Total(decimal price, int quantity);
}
[SingletonService]
public class PriceCalculator : IPriceCalculator
{
public decimal Total(decimal price, int quantity) => price * quantity;
}
[DependencyModule]
public partial class ShopModule;using DependencyModules.Runtime;
using Microsoft.Extensions.DependencyInjection;
using Shop;
var services = new ServiceCollection();
services.AddModule<ShopModule>();
var calculator = services.BuildServiceProvider().GetRequiredService<IPriceCalculator>();To start, refer to Getting started.