-
Notifications
You must be signed in to change notification settings - Fork 801
Improve DependencyInjection.AutoActivationExtensions #4219
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
Conversation
@geeknoid, just wondering. What is the replacement for |
81ba782
to
c0f550a
Compare
@martintmk @ericstj What's the actual initialization API that was added to dotnet/runtime? |
Ah, I think this is it: dotnet/runtime#87335 |
@steveharter Note that I'll add support for keyed services in a follow-on PR. I've got it all coded, but I need to wait for dotnet/runtime#89447 to be fixed, otherwise none of it works. |
- Avoid calling MakeGenericType when possible. - Delete the now-useless Hosting.StartupINitialization component.
c0f550a
to
3fb5f51
Compare
Yes - the decision was made to not create a new initializer concept but instead incorporate the ask into hosted services themselves. |
@steveharter can help with these - I believe you just need an |
Yes Here's a pattern from an earlier prototype of mine that has a fallback in case the host doesn't support the new interface: internal sealed class StartupActivator : IHostedLifecycleService
{
private bool _done;
Task IHostedLifecycleService.StartingAsync(CancellationToken cancellationToken) => Activate();
// For backwards compat with hosts that don't support IHostedLifecycleService, use StartAsync().
Task IHostedService.StartAsync(CancellationToken cancellationToken) => Activate();
Task IHostedLifecycleService.StartedAsync(CancellationToken cancellationToken) => Task.CompletedTask;
Task IHostedService.StopAsync(CancellationToken cancellationToken) => Task.CompletedTask;
Task IHostedLifecycleService.StoppedAsync(CancellationToken cancellationToken) => Task.CompletedTask;
Task IHostedLifecycleService.StoppingAsync(CancellationToken cancellationToken) => Task.CompletedTask;
private Task Activate()
{
if (!_done)
{
// activate the service(s) here
_done = true;
}
return Task.CompletedTask;
}
} |
Avoid calling MakeGenericType when possible.
Delete the now-useless Hosting.StartupINitialization component.
Microsoft Reviewers: Open in CodeFlow