Skip to content

Commit

Permalink
feat: add interface registration
Browse files Browse the repository at this point in the history
  • Loading branch information
ksavosteev committed May 6, 2024
1 parent 7a7da96 commit fd86907
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System.Net.Http;
using Polly.Retry;

namespace VirtoCommerce.ElasticAppSearch.Core.Services;

public interface IElasticAppSearchRetryPolicySelector
{
AsyncRetryPolicy<HttpResponseMessage> GetRetryPolicy();
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" PrivateAssets="All" />
<PackageReference Include="VirtoCommerce.SearchModule.Core" Version="3.800.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
using Polly.Extensions.Http;
using Polly.Retry;
using VirtoCommerce.ElasticAppSearch.Core.Models;
using VirtoCommerce.ElasticAppSearch.Core.Services;

namespace VirtoCommerce.ElasticAppSearch.Data.Services;

public class ElasticAppSearchPolicySelector
public class ElasticAppSearchPolicySelector : IElasticAppSearchRetryPolicySelector
{
private readonly ElasticAppSearchOptions _options;
private readonly ILogger<ElasticAppSearchApiClient> _logger;
Expand Down
4 changes: 2 additions & 2 deletions src/VirtoCommerce.ElasticAppSearch.Web/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void Initialize(IServiceCollection serviceCollection)
serviceCollection.AddSingleton<ElasticAppSearchProvider>();
serviceCollection.AddSingleton<ISearchFacetsQueryBuilder, SearchFacetsQueryBuilder>();
serviceCollection.AddSingleton<IAggregationsResponseBuilder, AggregationsResponseBuilder>();
serviceCollection.AddSingleton<ElasticAppSearchPolicySelector>();
serviceCollection.AddSingleton<IElasticAppSearchRetryPolicySelector, ElasticAppSearchPolicySelector>();

serviceCollection.AddHttpClient(ModuleConstants.ModuleName, (serviceProvider, httpClient) =>
{
Expand Down Expand Up @@ -71,7 +71,7 @@ public void Initialize(IServiceCollection serviceCollection)
})
.AddPolicyHandler((serviceProvider, _) =>
{
var policySelector = serviceProvider.GetRequiredService<ElasticAppSearchPolicySelector>();
var policySelector = serviceProvider.GetRequiredService<IElasticAppSearchRetryPolicySelector>();

return policySelector.GetRetryPolicy();
});
Expand Down

0 comments on commit fd86907

Please sign in to comment.