Skip to main content

📦 Installation

1️⃣ Add runtime package reference

Reference the core package in the consuming project:

<ItemGroup>
<PackageReference Include="GenDI" Version="x.y.z" />
</ItemGroup>

2️⃣ Add generator as analyzer

When consumed as NuGet, the source generator should be wired as analyzer/private assets behavior:

<ItemGroup>
<PackageReference Include="GenDI.SourceGenerator" Version="x.y.z"
PrivateAssets="all"
IncludeAssets="runtime; build; native; contentfiles; analyzers; buildtransitive" />
</ItemGroup>

3️⃣ Add attributes in your code

[ServiceInjection]
public interface IMyService { }

[Injectable<IMyService>(ServiceLifetime.Scoped)]
public sealed class MyService : IMyService
{
}

4️⃣ Register generated services

using <YourAssemblyName>.DependencyInjection;

services.AddGenDIServices();

5️⃣ Optional: coverage behavior toggle

[assembly: GenDI.GenDICoveration(true)]
  • true (default): generated extension remains included in coverage.
  • false: generated extension receives [ExcludeFromCodeCoverage].

🛠️ Local tooling and hooks

The repository ships local tools (csharpier, husky) in dotnet-tools.json.

  • 🔄 pre-commit formats and validates:
    • dotnet csharpier format .
    • dotnet test
  • 🔧 on fresh clone, the main project runs a pre-restore target that restores local tools and installs husky hooks.