-
Notifications
You must be signed in to change notification settings - Fork 0
Hosted Handlers
Frank Wagner edited this page Aug 27, 2020
·
1 revision
Hosuto adds a extension method AddHostedHandler (for IServiceCollection) to register a handler that will executed as hosted service. A handler is created from the hosts DI container and contains one method Execute to run the handler. Another overload of AddHostedHandler also allows to use a Func<IServiceProvider, CancellationToken, Task> delegate to set the handler code.
services.AddHostedHandler((sp, cancelToken) =>
{
var dispatcher = sp.GetRequiredService<IMessageDispatcher>();
dispatcher.RegisterRecipient(this);
return Task.CompletedTask;
});