Skip to content

Commit

Permalink
Merge pull request #614 from radixdlt/fix-ioc-registration-for-coreap…
Browse files Browse the repository at this point in the history
…i-provider

wip
  • Loading branch information
krzlabrdx authored Jan 15, 2024
2 parents e67357c + 66d53e1 commit 729bb25
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ public static GatewayApiBuilder AddNetworkGatewayApiCore(this IServiceCollection
// Request-scoped services
AddRequestServices(services);

// Node-Scoped services
AddNodeScopedServices(services);

// Transient (pooled) services
AddCoreApiHttpClient(services, out var coreApiHttpClientBuilder, out var coreNodeHealthCheckerClientBuilder);

Expand All @@ -136,6 +139,13 @@ private static void AddSingletonServices(IServiceCollection services)
services.TryAddSingleton<RequestTimeoutMiddleware>();
}

private static void AddNodeScopedServices(IServiceCollection services)
{
services.TryAddScoped<CoreApiNodeProvider>();
services.TryAddScoped<ICoreApiNodeProvider>(sp => sp.GetRequiredService<CoreApiNodeProvider>());
services.TryAddScoped<ICoreApiNodeConfigurator>(sp => sp.GetRequiredService<CoreApiNodeProvider>());
}

private static void AddRequestServices(IServiceCollection services)
{
services.TryAddScoped<IEntityHandler, DefaultEntityHandler>();
Expand All @@ -151,10 +161,8 @@ private static void AddRequestServices(IServiceCollection services)

private static void AddCoreApiHttpClient(IServiceCollection services, out IHttpClientBuilder coreApiHttpClientBuilder, out IHttpClientBuilder coreNodeHealthCheckerClientBuilder)
{
// NB - AddHttpClient is essentially like AddTransient, except it provides a HttpClient from the HttpClientFactory
// See https://docs.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests
coreApiHttpClientBuilder = services
.AddHttpClient<ICoreApiHandler, CoreApiHandler>()
.AddHttpClient<ICoreApiProvider, CoreApiProvider>()
.AddPolicyHandler((serviceProvider, _) =>
{
var retryCount = serviceProvider.GetRequiredService<IOptions<CoreApiIntegrationOptions>>().Value.MaxTransientErrorRetryCount;
Expand All @@ -165,6 +173,9 @@ private static void AddCoreApiHttpClient(IServiceCollection services, out IHttpC
})
.ConfigurePrimaryHttpMessageHandler(serviceProvider => ConfigureHttpClientHandler(serviceProvider.GetRequiredService<IOptions<NetworkOptions>>()));

services
.AddTransient<ICoreApiHandler, CoreApiHandler>();

coreNodeHealthCheckerClientBuilder = services
.AddHttpClient<ICoreNodeHealthChecker, CoreNodeHealthChecker>()
.ConfigurePrimaryHttpMessageHandler(serviceProvider => ConfigureHttpClientHandler(serviceProvider.GetRequiredService<IOptions<NetworkOptions>>()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public sealed class RadixAddressValidator : AbstractValidator<string>
{
public RadixAddressValidator(INetworkConfigurationProvider networkConfigurationProvider)
{
// TODO:
//Has to be sync.
RuleFor(x => x)
.CustomAsync(async (address, context, token) =>
{
Expand Down

0 comments on commit 729bb25

Please sign in to comment.