loresoft/Injectio

Support for hosted services

Closed this issue · 1 comments

Does it support registration of IHostedService and BackgroundService instances?

Yes it does. You just have to make sure that one of the Service Types is IHostedService and that duplicates are supported. If you look at what AddHostedService actually does, it just registers the services as a singleton with service type IHostedService

https://github.com/dotnet/runtime/blob/6a94e2a137048f7ef9280537a1d2dbcf4fab19b8/src/libraries/Microsoft.Extensions.Hosting.Abstractions/src/ServiceCollectionHostedServiceExtensions.cs#L22

[RegisterSingleton(Duplicate = DuplicateStrategy.Append)]
public class HostedService : IHostedService{ }

OR

[RegisterSingleton(ServiceType = typeof(IHostedService), Duplicate = DuplicateStrategy.Append)]
public class HostedService : BackgroundService{ }