Skip to content

Commit b75cea3

Browse files
committed
fix: resolve middleware client registrations
1 parent afa4912 commit b75cea3

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/Transmitly.Microsoft.Extensions.DependencyInjection/ServiceCollectionCommunicationClientFactory.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,14 @@ public override ICommunicationsClient CreateClient(ICreateCommunicationsClientCo
110110
_services.AddSingleton<DefaultCommunicationsClient>();
111111
else
112112
{
113-
//middleware before us has created a client, register it's type instead
113+
// Rebuild the default client via DI so service-provider-backed factories are used.
114+
// Custom wrapper clients may depend on runtime-only constructor arguments, so keep
115+
// those as the already-created instance instead of asking DI to construct them.
114116
previousClientType = previous.GetType();
115-
_services.AddSingleton(previousClientType);
117+
if (previousClientType == typeof(DefaultCommunicationsClient))
118+
_services.AddSingleton(previousClientType);
119+
else
120+
_services.AddSingleton(previousClientType, previous);
116121

117122
}
118123

0 commit comments

Comments
 (0)