Skip to content

DependencyModulesRegistration code that the generator writes

DependencyModules is a source generator for Microsoft.Extensions.DependencyInjection. You put attributes on your classes. The generator writes the registrations when you compile.

DependencyModules

Example ​

csharp
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;
csharp
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.

MIT license