@@ -16,6 +16,19 @@ public static class ServiceCollectionHostedServiceExtensions
1616 /// <summary>
1717 /// Add an <see cref="IHostedService"/> registration for the given type.
1818 /// </summary>
19+ /// <remarks>
20+ /// Note that this creates registration for <see cref="IHostedService"/> specifically. Not for the actual <c>THostedService</c> type.
21+ /// If you want to register the actual type, you must do so separately.
22+ /// </remarks>
23+ /// <example>
24+ /// <para>
25+ /// The following code shows how to register a hosted service while also registering the actual <c>THostedService</c> type.
26+ /// </para>
27+ /// <code language="csharp">
28+ /// services.AddSingleton<SomeService>();
29+ /// services.AddHostedService(sp => sp.GetRequiredService<SomeService>());
30+ /// </code>
31+ /// </example>
1932 /// <typeparam name="THostedService">An <see cref="IHostedService"/> to register.</typeparam>
2033 /// <param name="services">The <see cref="IServiceCollection"/> to register with.</param>
2134 /// <returns>The original <see cref="IServiceCollection"/>.</returns>
@@ -30,6 +43,19 @@ public static class ServiceCollectionHostedServiceExtensions
3043 /// <summary>
3144 /// Add an <see cref="IHostedService"/> registration for the given type.
3245 /// </summary>
46+ /// <remarks>
47+ /// Note that this creates registration for <see cref="IHostedService"/> specifically. Not for the actual <c>THostedService</c> type.
48+ /// If you want to register the actual type, you must do so separately.
49+ /// </remarks>
50+ /// <example>
51+ /// <para>
52+ /// The following code shows how to register a hosted service while also registering the actual <c>THostedService</c> type.
53+ /// </para>
54+ /// <code language="csharp">
55+ /// services.AddSingleton<SomeService>(implementationFactory);
56+ /// services.AddHostedService(sp => sp.GetRequiredService<SomeService>());
57+ /// </code>
58+ /// </example>
3359 /// <typeparam name="THostedService">An <see cref="IHostedService"/> to register.</typeparam>
3460 /// <param name="services">The <see cref="IServiceCollection"/> to register with.</param>
3561 /// <param name="implementationFactory">A factory to create new instances of the service implementation.</param>
0 commit comments