Skip to content

Commit

Permalink
Correction for mapper registration in DI container
Browse files Browse the repository at this point in the history
  • Loading branch information
spencerohegartyDfE committed Sep 11, 2024
1 parent d0f0c5f commit e31ca5a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public CognitiveSearchServiceAdapter(
/// Makes call to underlying azure cognitive search service and uses the prescribed mapper
/// to adapt the raw Azure search results to the <see cref="SearchResults"/> type.
/// </summary>
/// <param name="searchRequest">
/// <param name="searchServiceAdapterRequest">
/// Prescribes the context of the search including the keyword and collection target.
/// </param>
/// <returns>
Expand All @@ -69,7 +69,7 @@ public CognitiveSearchServiceAdapter(
/// <exception cref="ArgumentException">
/// Exception thrown if the data cannot be mapped
/// </exception>
public async Task<SearchResults> SearchAsync(SearchServiceAdapterRequest searchRequest)
public async Task<SearchResults> SearchAsync(SearchServiceAdapterRequest searchServiceAdapterRequest)
{
SearchOptions searchOptions = new()
{
Expand All @@ -78,21 +78,21 @@ public async Task<SearchResults> SearchAsync(SearchServiceAdapterRequest searchR
IncludeTotalCount = _azureSearchOptions.IncludeTotalCount,
};

searchRequest.SearchFields?.ToList()
searchServiceAdapterRequest.SearchFields?.ToList()
.ForEach(searchOptions.SearchFields.Add);

searchRequest.Facets?.ToList()
searchServiceAdapterRequest.Facets?.ToList()
.ForEach(searchOptions.Facets.Add);

Response<SearchResults<TSearchResult>> searchResults =
await _searchByKeywordService.SearchAsync<TSearchResult>(
searchRequest.SearchKeyword,
searchServiceAdapterRequest.SearchKeyword,
_azureSearchOptions.SearchIndex,
searchOptions
)
.ConfigureAwait(false) ??
throw new ApplicationException(
$"Unable to derive search results based on input {searchRequest.SearchKeyword}.");
$"Unable to derive search results based on input {searchServiceAdapterRequest.SearchKeyword}.");

var results = new SearchResults()
{
Expand Down
7 changes: 3 additions & 4 deletions Dfe.Data.SearchPrototype/Infrastructure/CompositionRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Dfe.Data.SearchPrototype.SearchForEstablishments.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Models = Dfe.Data.SearchPrototype.SearchForEstablishments.Models;

namespace Dfe.Data.SearchPrototype.Infrastructure;

Expand Down Expand Up @@ -52,10 +51,10 @@ public static void AddCognitiveSearchAdaptorServices(this IServiceCollection ser
.GetSection(nameof(SearchByKeywordCriteria))
.Bind(settings));

services.AddScoped(typeof(ISearchServiceAdapter), typeof(CognitiveSearchServiceAdapter<SearchResults>));
services.AddSingleton(typeof(IMapper<Pageable<SearchResult<Models.Establishment>>, Models.EstablishmentResults>), typeof(PageableSearchResultsToEstablishmentResultsMapper));
services.AddScoped(typeof(ISearchServiceAdapter), typeof(CognitiveSearchServiceAdapter<DataTransferObjects.Establishment>));
services.AddSingleton(typeof(IMapper<Pageable<SearchResult<DataTransferObjects.Establishment>>, EstablishmentResults>), typeof(PageableSearchResultsToEstablishmentResultsMapper));
services.AddSingleton<IMapper<Dictionary<string, IList<Azure.Search.Documents.Models.FacetResult>>, EstablishmentFacets>, AzureFacetResultToEstablishmentFacetsMapper>();
services.AddSingleton<IMapper<DataTransferObjects.Establishment, Address>, AzureSearchResultToAddressMapper>();
services.AddSingleton<IMapper<DataTransferObjects.Establishment, SearchForEstablishments.Models.Establishment>, AzureSearchResultToEstablishmentMapper>();
services.AddSingleton<IMapper<DataTransferObjects.Establishment, Establishment>, AzureSearchResultToEstablishmentMapper>();
}
}

0 comments on commit e31ca5a

Please sign in to comment.