JasperFx.SourceGenerator 2.56.0

JasperFx.SourceGenerator

Roslyn source generators for JasperFx, all reflection-free for fast cold start and trim/AOT-friendly builds. This single analyzer package bundles five generators:

Generator What it does
DescriptionGenerator Generates IDescribeMyself.ToDescription() for OptionsDescription types, eliminating runtime reflection on options classes that surface in diagnostic snapshots (CritterWatch, etc.).
CommandDiscoveryGenerator Emits a compile-time manifest of IJasperFxCommand types so dotnet run -- <command> lookups skip runtime assembly scanning.
InputParserGenerator Emits IGeneratedInputParser implementations for command input models, parsing CLI arguments/flags without runtime reflection.
ExtensionDiscoveryGenerator Emits a compile-time JasperFx.Generated.DiscoveredExtensions type list of IJasperFxExtension / [JasperFxAssembly]-declared extension types so framework extension loaders skip assembly scanning.
ServiceRegistrationGenerator Emits actual IServiceCollection registrations (JasperFx.Generated.GeneratedServiceRegistrations.Register) for [JasperFxService]-annotated types — see below.

Renamed from JasperFx.SourceGeneration. The command-discovery and input-parser generators previously shipped in the JasperFx.SourceGeneration (noun) package, which is now retired. Reference JasperFx.SourceGenerator (singular) instead — its version tracks the JasperFx package.

Install

<PackageReference Include="JasperFx.SourceGenerator"
                  PrivateAssets="all"
                  OutputItemType="Analyzer"
                  ReferenceOutputAssembly="false" />

Reference it as an analyzer/source-generator only — there's no runtime API. For OptionsDescription, apply the [GenerateDescription] attribute to a partial class that implements IDescribeMyself and a ToDescription() method is generated. The command-discovery and input-parser output is consumed transparently by JasperFx.CommandLine.

Service registrations

Annotate a concrete class with [JasperFxService(typeof(TService), ServiceLifetime)] to have the generator emit a real DI registration for it. The generator produces a per-assembly JasperFx.Generated.GeneratedServiceRegistrations.Register(IServiceCollection) method of plain services.Add(new ServiceDescriptor(...)) calls — no reflection, trim/AOT-clean.

[JasperFxService(typeof(IWolverineExtension), ServiceLifetime.Singleton)]
public class MyExtension : IWolverineExtension { }

// Open generic service types are closed from the implemented interface (=> IValidator<Foo>):
[JasperFxService(typeof(IValidator<>), ServiceLifetime.Scoped)]
public class FooValidator : IValidator<Foo> { }

Apply the attribute multiple times to register one implementation against several service types. At startup, apply everything discovered across the loaded assemblies (reflection-free on the generated side; a no-op when the generator wasn't run, so a reflective fallback still applies):

JasperFx.GeneratedExtensionManifest.RegisterAllDiscoveredServices(services);

Only assemblies that are eligible emit a manifest — those carrying a [JasperFxAssembly]-derived attribute, or executable (entry) assemblies — matching the ExtensionDiscoveryGenerator gate.

Performance

The generators replace runtime reflection with code emitted at compile time. Measured against the reflection fallback with BenchmarkDotNet (src/CommandLineBenchmarks, Apple M5 Max, .NET 9):

Workload Reflection Generated
Build handlers for a small input model ~2.8 µs ~0.43 µs (≈6.5× faster)
Build handlers for a large input model ~8.5 µs ~0.48 µs (≈18× faster)
Full dotnet run -- <command> parse baseline ≈2–4.5× faster, ≈2–3× fewer allocations

The win is eliminating reflection (PropertyInfo.SetValue, converter lookups, assembly scanning), not eliminating allocation — the generated parser still allocates its handler list and delegates. Earlier "thousands of times faster / zero allocation" figures were a measurement artifact: the generators were emitting nothing, so the benchmark compared reflection against a no-op. The numbers above reflect the generators actually running.

Documentation

Full docs at https://jasperfx.net.

Repo: github.com/JasperFx/jasperfx.

Showing the top 20 packages that depend on JasperFx.SourceGenerator.

Packages Downloads
WolverineFx
Build Robust Event Driven Architectures with Simpler Code
4

.NET Standard 2.0

  • No dependencies.

Version Downloads Last updated
2.57.2 0 2026-08-30
2.57.1 0 2026-08-28
2.57.0 0 2026-08-27
2.56.0 10 2026-08-27
2.55.0 0 2026-08-23
2.54.0 0 2026-08-21
2.53.0 0 2026-08-20
2.52.1 0 2026-08-19
2.52.0 0 2026-08-18
2.51.0 0 2026-08-17
2.50.0 0 2026-08-17
2.49.0 0 2026-08-16
2.48.0 0 2026-08-15
2.47.0 0 2026-08-11
2.46.0 0 2026-08-10
2.45.0 0 2026-08-08
2.44.0 0 2026-08-07
2.43.0 0 2026-08-06
2.42.2 0 2026-08-06
2.42.1 0 2026-08-06
2.41.0 0 2026-08-05
2.40.0 0 2026-08-05
2.39.5 0 2026-08-05
2.39.4 0 2026-08-04
2.39.3 0 2026-08-04
2.39.2 0 2026-08-04
2.39.1 0 2026-08-04
2.39.0 0 2026-08-04
2.38.0 0 2026-08-03
2.37.3 0 2026-08-02
2.37.2 0 2026-08-02
2.37.1 0 2026-08-02
2.37.0 0 2026-07-31
2.36.3 0 2026-07-30
2.36.2 0 2026-07-27
2.36.1 0 2026-07-26
2.36.0 0 2026-07-26
2.35.0 0 2026-07-24
2.34.0 0 2026-07-22
2.33.1 0 2026-07-22
2.33.0 0 2026-07-21
2.32.0 0 2026-07-20
2.31.0 0 2026-07-20
2.30.2 0 2026-07-20
2.30.1 0 2026-07-19
2.30.0 0 2026-07-18
2.29.1 0 2026-07-18
2.29.0 0 2026-07-17
2.28.1 0 2026-07-17
2.28.0 0 2026-07-17
2.27.0 0 2026-07-12
2.26.0 0 2026-07-10
2.25.0 0 2026-07-09
2.24.1 0 2026-07-08
2.24.0 0 2026-07-07
2.23.0 0 2026-07-07
2.22.0 0 2026-07-07
2.21.1 0 2026-07-07
2.21.0 0 2026-07-07
2.20.0 0 2026-07-06
2.19.1 0 2026-07-06
2.19.0 0 2026-07-05
2.18.1 0 2026-06-28
2.18.0 0 2026-06-27
2.17.0 0 2026-06-27
2.16.0 0 2026-06-25
2.15.0 0 2026-06-24
2.14.2 0 2026-06-24
2.14.1 0 2026-06-24
2.14.0 0 2026-06-24
2.13.3 0 2026-06-23
2.13.2 0 2026-06-22
2.13.1 0 2026-06-18
2.13.0 0 2026-06-17
2.12.0 0 2026-06-14
2.11.0 0 2026-06-14
2.10.0 0 2026-06-13
2.9.13 0 2026-06-13
2.9.12 0 2026-06-13
2.9.11 0 2026-06-13
2.9.10 0 2026-06-12
2.9.9 0 2026-06-11
2.9.8 0 2026-06-11
2.9.7 0 2026-06-11
2.9.6 0 2026-06-10
2.9.5 0 2026-06-10
2.9.4 0 2026-06-10
2.9.3 0 2026-06-10
2.9.2 0 2026-06-09
2.9.1 0 2026-06-09
2.9.0 0 2026-06-08
2.8.2 0 2026-06-05
2.8.1 0 2026-06-05
2.8.0 0 2026-06-02
2.6.1 0 2026-06-02
2.6.0 0 2026-06-02
2.5.0 0 2026-06-02
2.4.1 0 2026-06-01
2.4.0 0 2026-05-31
2.3.0 0 2026-05-31
2.2.7 0 2026-05-29
2.2.6 0 2026-05-29
2.2.5 0 2026-05-29
2.2.4 0 2026-05-29
2.2.3 0 2026-05-29
2.2.2 0 2026-05-29
2.2.1 0 2026-05-29
2.2.0 0 2026-05-27
2.1.4 0 2026-05-27
2.1.3 0 2026-05-27
2.1.2 0 2026-05-27
2.0.1 0 2026-05-24
2.0.0 0 2026-05-21
2.0.0-rc.3 0 2026-05-21
2.0.0-rc.2 0 2026-05-20
2.0.0-rc.1 0 2026-05-20
2.0.0-alpha.9 0 2026-05-19