Skip to content

Commit 4c356d0

Browse files
MichaelDeutschCodingbuyaa-ngewarren
authored
Document counterintuitive AddHostedService behavior (dotnet#9141)
* Document counterintuitive AddHostedService behavior See dotnet/runtime#52747 for discussion about this issue. * Update ServiceCollectionHostedServiceExtensions.xml * Fix link in ServiceCollectionHostedServiceExtensions.xml * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com> * Fix CDATA parse error --------- Co-authored-by: Buyaa Namnan <buyankhishig.namnan@microsoft.com> Co-authored-by: Genevieve Warren <24882762+gewarren@users.noreply.github.com>
1 parent 4355096 commit 4c356d0

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

xml/Microsoft.Extensions.DependencyInjection/ServiceCollectionHostedServiceExtensions.xml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@
6969
<param name="services">The <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" /> to register with.</param>
7070
<summary>Add an <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> registration for the given type.</summary>
7171
<returns>The original <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" />.</returns>
72-
<remarks>To be added.</remarks>
72+
<remarks>
73+
<format type="text/markdown"><![CDATA[
74+
> [!NOTE]
75+
> You shouldn't call this method multiple times for the same class. Doing so will only register the first HostedService you provide. To add multiple HostedServices, use <xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton%60%601(Microsoft.Extensions.DependencyInjection.IServiceCollection)> for each implementation of <xref:Microsoft.Extensions.Hosting.IHostedService> explicitly.
76+
]]></format>
77+
</remarks>
7378
</Docs>
7479
</Member>
7580
<Member MemberName="AddHostedService&lt;THostedService&gt;">
@@ -110,7 +115,12 @@
110115
<param name="implementationFactory">A factory to create new instances of the service implementation.</param>
111116
<summary>Add an <see cref="T:Microsoft.Extensions.Hosting.IHostedService" /> registration for the given type.</summary>
112117
<returns>The original <see cref="T:Microsoft.Extensions.DependencyInjection.IServiceCollection" />.</returns>
113-
<remarks>To be added.</remarks>
118+
<remarks>
119+
<format type="text/markdown"><![CDATA[
120+
> [!NOTE]
121+
> You shouldn't call this method multiple times for the same class. Doing so will only register the first HostedService you provide. To add multiple HostedServices, use <xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionServiceExtensions.AddSingleton%60%601(Microsoft.Extensions.DependencyInjection.IServiceCollection,System.Func{System.IServiceProvider,%60%600})> for each implementation of <xref:Microsoft.Extensions.Hosting.IHostedService> explicitly.
122+
]]></format>
123+
</remarks>
114124
</Docs>
115125
</Member>
116126
</Members>

0 commit comments

Comments
 (0)