Phymnary.SugarPot.DependencyInjection.Roslyn 1.0.0

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Phymnary.SugarPot.DependencyInjection.Roslyn --version 1.0.0
                    
NuGet\Install-Package Phymnary.SugarPot.DependencyInjection.Roslyn -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Phymnary.SugarPot.DependencyInjection.Roslyn" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Phymnary.SugarPot.DependencyInjection.Roslyn" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Phymnary.SugarPot.DependencyInjection.Roslyn" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Phymnary.SugarPot.DependencyInjection.Roslyn --version 1.0.0
                    
#r "nuget: Phymnary.SugarPot.DependencyInjection.Roslyn, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Phymnary.SugarPot.DependencyInjection.Roslyn@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Phymnary.SugarPot.DependencyInjection.Roslyn&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Phymnary.SugarPot.DependencyInjection.Roslyn&version=1.0.0
                    
Install as a Cake Tool

Phymnary.SugarPot.DependencyInjection.Roslyn

Roslyn analyzer + incremental source generator for convention-based dependency registration.

This project works with Phymnary.SugarPot.DependencyInjection attributes to generate IServiceCollection registration code at compile time.

What this project provides

  • Incremental generator: AutoRegisterGenerator
  • Analyzer: AutoRegisterAnalyzer
  • Diagnostic descriptors for invalid service decorations

Generation model

The generator scans for:

  • [Service(Lifetime.X)] on implementation classes
  • [Auto] on module classes (must be partial)

For each [Auto] partial class, it generates registration code that adds all discovered [Service] types to IServiceCollection using the configured lifetime.

Service type resolution rules

For a class decorated with [Service], generated registration chooses service type in this order:

  1. If IsSelf = true → register implementation as itself
  2. Otherwise first implemented interface of the class
  3. Otherwise first interface from base type
  4. Otherwise implementation type itself

Lifetime is mapped to:

  • Lifetime.Singleton → AddSingleton<TService, TImpl>
  • Lifetime.Scoped → AddScoped<TService, TImpl>
  • Lifetime.Transient → AddTransient<TService, TImpl>

Analyzer diagnostics

Current diagnostic:

  • SPDI0001 (Error): class with [Service] cannot be abstract or generic.

Conventions and requirements

  • [Auto] target class must be partial (required for source generation).
  • [Service] classes must be concrete, non-generic classes.
  • Generator relies on attributes from Phymnary.SugarPot.DependencyInjection namespace.

Example

using Phymnary.SugarPot.DependencyInjection;

[Service(Lifetime.Scoped)]
public sealed class UserService : IUserService
{
}

[Auto]
public partial class ApplicationModule
{
}

Generated code will add a scoped registration similar to:

services.AddScoped<IUserService, UserService>();

Project structure

  • Components/AutoRegister/AutoRegisterGenerator*.cs - generator pipeline + syntax emit
  • Components/AutoRegister/AutoRegisterAnalyzer.cs - semantic validation
  • Diagnostics/DiagnosticDescriptors.cs - analyzer metadata
  • Constants/GeneratorConstant.cs - shared constants

Dependencies

  • Microsoft.CodeAnalysis.Analyzers
  • Microsoft.CodeAnalysis.CSharp.Workspaces

Local development notes

  • Build this project to validate generator/analyzer behavior.
  • Validate generated output in consumer projects using [Auto] and [Service].
  • Keep analyzer metadata in sync with AnalyzerReleases.Shipped.md and AnalyzerReleases.Unshipped.md.

Target framework

  • .NET Standard 2.0 (analyzer/generator compatibility target)
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated