-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DefineCriticalErrorAction access to IServiceProvider #7039
Comments
It is already possible to use var builder = Host.CreateApplicationBuilder(args);
IHostApplicationLifetime lifetime = null;
var endpointConfiguration = new EndpointConfiguration("example");
var routing = endpointConfiguration.UseTransport(new LearningTransport());
endpointConfiguration.UseSerialization<SystemJsonSerializer>();
endpointConfiguration.DefineCriticalErrorAction((context, cancellationToken) => OnCriticalError(context, cancellationToken, lifetime));
builder.UseNServiceBus(endpointConfiguration);
var app = builder.Build();
lifetime = app.Services.GetRequiredService<IHostApplicationLifetime>();
app.Run();
static Task OnCriticalError(ICriticalErrorContext context, CancellationToken cancellationToken, IHostApplicationLifetime lifetime)
{
lifetime.StopApplication();
return Task.CompletedTask;
} |
We have an application portfolio spanning 150 repos containing deployable code; mixture of ASP.NET and Windows Services. In order to keep this maintainable and consistent, we have created a highly opinionated framework on top of ASP.NET. This sets up authentication, logging, metrics, and a bunch of other things. When using external libraries such as NServiceBus, Quartz or GraphQL, we wrap them in a system that allows us to easily set them up with the rest of the system. Your example takes advantage of C# closures and the fact that everything is in the same file. This is not something our applications can take advantage. |
Hi @dnv-kimbell Thanks for providing more context to this feature request. Regards |
Describe the feature.
We are implementing
DefineCriticalErrorAction()
to shut down the application. In your documentation there is a mention ofIHostApplicationLifetime.Stop
, but the challenge is thatICriticalErrorContext
doesn't give us access to anIServiceProvider
where we can get access toIHostApplicationLifetime
.Our workaround is to have a hosted services that polls a static property where
DefineCriticalErrorAction()
can set theICriticalErrorContext
.Not pretty.
Additional Context
No response
The text was updated successfully, but these errors were encountered: