Skip to content

Commit

Permalink
⚡️ avoid registering HttpClient if not using http(s) protocol (#147)
Browse files Browse the repository at this point in the history
  • Loading branch information
Odonno authored Nov 28, 2024
1 parent 8a59619 commit a7a5a30
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ public static SurrealDbBuilder AddSurreal<T>(
if (configuration.Endpoint is null)
throw new ArgumentNullException(nameof(configuration), "The endpoint is required.");

RegisterHttpClient(services, configuration.Endpoint);
bool shouldRegisterHttpClient = new Uri(configuration.Endpoint).Scheme is "http" or "https";
if (shouldRegisterHttpClient)
{
RegisterHttpClient(services, configuration.Endpoint);
}

var classClientType = typeof(SurrealDbClient);
var interfaceClientType = typeof(ISurrealDbClient);
Expand Down Expand Up @@ -195,7 +199,7 @@ private static void RegisterSurrealDbClient<T>(
return new SurrealDbClient(
configuration,
serviceProvider,
serviceProvider.GetRequiredService<IHttpClientFactory>(),
serviceProvider.GetService<IHttpClientFactory>(),
configureCborOptions,
serviceProvider.GetService<ILoggerFactory>()
);
Expand All @@ -210,7 +214,7 @@ private static void RegisterSurrealDbClient<T>(
return new SurrealDbClient(
configuration,
serviceProvider,
serviceProvider.GetRequiredService<IHttpClientFactory>(),
serviceProvider.GetService<IHttpClientFactory>(),
configureCborOptions,
serviceProvider.GetService<ILoggerFactory>()
);
Expand All @@ -225,7 +229,7 @@ private static void RegisterSurrealDbClient<T>(
return new SurrealDbClient(
configuration,
serviceProvider,
serviceProvider.GetRequiredService<IHttpClientFactory>(),
serviceProvider.GetService<IHttpClientFactory>(),
configureCborOptions,
serviceProvider.GetService<ILoggerFactory>()
);
Expand Down

0 comments on commit a7a5a30

Please sign in to comment.