Skip to content

Latest commit

 

History

History
54 lines (39 loc) · 2.14 KB

File metadata and controls

54 lines (39 loc) · 2.14 KB

SquidStd.Generators

Roslyn source generators for SquidStd compile-time registration helpers.

Install

dotnet add package SquidStd.Generators

Usage

The event listener generator discovers concrete IEventListener<TEvent> implementations marked with [RegisterEventListener] and generates a DryIoc registration extension:

using SquidStd.Abstractions.Attributes;
using SquidStd.Core.Interfaces.Events;

[RegisterEventListener]
public sealed class PingListener : IEventListener<PingEvent>
{
    public Task HandleAsync(PingEvent eventData, CancellationToken cancellationToken = default)
        => Task.CompletedTask;
}

container.RegisterGeneratedEventListeners();

The generated method reuses the normal RegisterEventListener<TEvent,TListener>() runtime path, so listener activation stays compatible with SquidStd.Services.Core. Each registration family has its own marker attribute and generated extension method, all calling the same runtime APIs as manual registration (RegisterStdService, RegisterConfigSection, AddJobHandler, RegisterScriptModule).

Key types

Marker attribute Generated method
[RegisterEventListener] RegisterGeneratedEventListeners()
[RegisterStdService(typeof(IMyService), Priority = 10)] RegisterGeneratedStdServices()
[RegisterConfigSection("workers", Priority = -50)] RegisterGeneratedConfigSections()
[RegisterJobHandler] RegisterGeneratedJobHandlers()
[RegisterScriptModule] with [ScriptModule("name")] RegisterGeneratedScriptModules()

Related

Tutorial: Source generators: registration

License

MIT - part of SquidStd.