diff --git a/Dfe.Data.SearchPrototype/Infrastructure/CompositionRoot.cs b/Dfe.Data.SearchPrototype/Infrastructure/CompositionRoot.cs
index 47dbe99..e4ed4b1 100644
--- a/Dfe.Data.SearchPrototype/Infrastructure/CompositionRoot.cs
+++ b/Dfe.Data.SearchPrototype/Infrastructure/CompositionRoot.cs
@@ -24,13 +24,10 @@ public static class CompositionRoot
///
/// The originating application services onto which to register the search dependencies.
///
- ///
- /// The originating configuration block from which to derive search service settings.
- ///
///
/// The exception thrown if no valid is provisioned.
///
- public static void AddCognitiveSearchAdaptorServices(this IServiceCollection services, IConfiguration configuration)
+ public static void AddCognitiveSearchAdaptorServices(this IServiceCollection services)
{
if (services is null)
{
diff --git a/Dfe.Data.SearchPrototype/Infrastructure/Tests/Integration/TestHarness/CompositionRootServiceProvider.cs b/Dfe.Data.SearchPrototype/Infrastructure/Tests/Integration/TestHarness/CompositionRootServiceProvider.cs
index 13fdce0..362562b 100644
--- a/Dfe.Data.SearchPrototype/Infrastructure/Tests/Integration/TestHarness/CompositionRootServiceProvider.cs
+++ b/Dfe.Data.SearchPrototype/Infrastructure/Tests/Integration/TestHarness/CompositionRootServiceProvider.cs
@@ -15,7 +15,7 @@ public IServiceProvider SetUpServiceProvider(IConfiguration config)
services.AddSingleton(config);
// this is the extension method to add all the dependencies
- services.AddCognitiveSearchAdaptorServices(config);
+ services.AddCognitiveSearchAdaptorServices();
// Replace Common.Infrastructure services with mocks
services.RemoveAll();
@@ -25,10 +25,10 @@ public IServiceProvider SetUpServiceProvider(IConfiguration config)
.WithSearchResults()
.Create())
.Create();
- services.AddScoped(provider => mockSearchService);
+ services.AddScoped(provider => mockSearchService);
services.RemoveAll();
var mockFilterExpressionBuilder = new FilterExpressionBuilderTestDouble().Create();
- services.AddScoped(provider => mockFilterExpressionBuilder);
+ services.AddScoped(provider => mockFilterExpressionBuilder);
return services.BuildServiceProvider();
}
diff --git a/Dfe.Data.SearchPrototype/SearchForEstablishments/ByKeyword/Usecase/SearchByKeywordUseCase.cs b/Dfe.Data.SearchPrototype/SearchForEstablishments/ByKeyword/Usecase/SearchByKeywordUseCase.cs
index e708f0a..98a5ec2 100644
--- a/Dfe.Data.SearchPrototype/SearchForEstablishments/ByKeyword/Usecase/SearchByKeywordUseCase.cs
+++ b/Dfe.Data.SearchPrototype/SearchForEstablishments/ByKeyword/Usecase/SearchByKeywordUseCase.cs
@@ -1,7 +1,6 @@
using Dfe.Data.SearchPrototype.Common.CleanArchitecture.Application.UseCase;
using Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.ServiceAdapters;
using Dfe.Data.SearchPrototype.SearchForEstablishments.Models;
-using Microsoft.Extensions.Options;
namespace Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.Usecase;
@@ -14,7 +13,7 @@ namespace Dfe.Data.SearchPrototype.SearchForEstablishments.ByKeyword.Usecase;
public sealed class SearchByKeywordUseCase : IUseCase
{
private readonly ISearchServiceAdapter _searchServiceAdapter;
- private readonly SearchByKeywordCriteria _searchByKeywordCriteriaOptions;
+ private readonly SearchByKeywordCriteria _searchByKeywordCriteria;
///
/// The following dependencies include the core cognitive search service definition,
@@ -24,7 +23,7 @@ public sealed class SearchByKeywordUseCase : IUseCase
- ///
+ ///
/// The define the search fields and facets on
/// which to conduct the underlying search. This is defined in configuration using
/// the options pattern as follows (note: fields and facets used are for explanatory use only),
@@ -44,10 +43,10 @@ public sealed class SearchByKeywordUseCase : IUseCase
public SearchByKeywordUseCase(
ISearchServiceAdapter searchServiceAdapter,
- IOptions searchByKeywordCriteriaOptions)
+ SearchByKeywordCriteria searchByKeywordCriteria)
{
- ArgumentNullException.ThrowIfNull(searchByKeywordCriteriaOptions);
- _searchByKeywordCriteriaOptions = searchByKeywordCriteriaOptions.Value;
+ ArgumentNullException.ThrowIfNull(searchByKeywordCriteria);
+ _searchByKeywordCriteria = searchByKeywordCriteria;
_searchServiceAdapter = searchServiceAdapter;
}
@@ -77,8 +76,8 @@ public async Task HandleRequest(SearchByKeywordRequest
await _searchServiceAdapter.SearchAsync(
new SearchServiceAdapterRequest(
request.SearchKeyword,
- _searchByKeywordCriteriaOptions.SearchFields,
- _searchByKeywordCriteriaOptions.Facets,
+ _searchByKeywordCriteria.SearchFields,
+ _searchByKeywordCriteria.Facets,
request.FilterRequests));
return results switch
diff --git a/Dfe.Data.SearchPrototype/SearchForEstablishments/CompositionRoot.cs b/Dfe.Data.SearchPrototype/SearchForEstablishments/CompositionRoot.cs
index 147bf9f..fb72a75 100644
--- a/Dfe.Data.SearchPrototype/SearchForEstablishments/CompositionRoot.cs
+++ b/Dfe.Data.SearchPrototype/SearchForEstablishments/CompositionRoot.cs
@@ -3,6 +3,7 @@
using Dfe.Data.SearchPrototype.SearchForEstablishments.Models;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Options;
namespace Dfe.Data.SearchPrototype.SearchForEstablishments;
@@ -32,12 +33,17 @@ public static void AddSearchForEstablishmentServices(this IServiceCollection ser
throw new ArgumentNullException(nameof(services),
"A service collection is required to configure the search by keyword use-case.");
}
+
services.AddOptions()
.Configure(
(settings, configuration) =>
configuration
.GetSection(nameof(SearchByKeywordCriteria))
.Bind(settings));
+
+ services.AddSingleton(serviceProvider =>
+ serviceProvider.GetRequiredService>().Value);
+
services.AddScoped, SearchByKeywordUseCase>();
}
}
diff --git a/Dfe.Data.SearchPrototype/Tests/Integration/CompositionRootTests.cs b/Dfe.Data.SearchPrototype/Tests/Integration/CompositionRootTests.cs
index f68acdb..ad8006b 100644
--- a/Dfe.Data.SearchPrototype/Tests/Integration/CompositionRootTests.cs
+++ b/Dfe.Data.SearchPrototype/Tests/Integration/CompositionRootTests.cs
@@ -31,5 +31,6 @@ public async Task AddSearchForEstablishmentServices_CanCreateUsecase()
var response = await usecase.HandleRequest(new SearchByKeywordRequest("searchkeyword"));
response.Should().NotBeNull();
+ response.Status.Should().Be(SearchResponseStatus.Success);
}
}
diff --git a/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ByKeyword/SearchByKeywordUseCaseTests.cs b/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ByKeyword/SearchByKeywordUseCaseTests.cs
index cb09a9a..fb02652 100644
--- a/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ByKeyword/SearchByKeywordUseCaseTests.cs
+++ b/Dfe.Data.SearchPrototype/Tests/SearchForEstablishments/ByKeyword/SearchByKeywordUseCaseTests.cs
@@ -12,9 +12,9 @@ namespace Dfe.Data.SearchPrototype.Tests.SearchForEstablishments.ByKeyword;
public sealed class SearchByKeywordUseCaseTests
{
private readonly SearchByKeywordUseCase _useCase;
- private ISearchServiceAdapter _searchServiceAdapter;
- private SearchResults _searchResults;
- private SearchByKeywordCriteria _options = SearchByKeywordCriteriaTestDouble.Create();
+ private readonly ISearchServiceAdapter _searchServiceAdapter;
+ private readonly SearchResults _searchResults;
+ private readonly SearchByKeywordCriteria _searchByKeywordCriteriaStub = SearchByKeywordCriteriaTestDouble.Create();
public SearchByKeywordUseCaseTests()
{
@@ -23,7 +23,7 @@ public SearchByKeywordUseCaseTests()
_searchServiceAdapter =
SearchServiceAdapterTestDouble.MockFor(_searchResults);
- _useCase = new(_searchServiceAdapter, IOptionsTestDouble.IOptionsMockFor(_options));
+ _useCase = new(_searchServiceAdapter, _searchByKeywordCriteriaStub);
}
[Fact]
@@ -45,8 +45,8 @@ public async Task HandleRequest_ValidRequest_CallsAdapterWithMappedRequestParams
// assert
adapterRequest!.SearchKeyword.Should().Be(request.SearchKeyword);
- adapterRequest!.SearchFields.Should().BeEquivalentTo(_options.SearchFields);
- adapterRequest!.Facets.Should().BeEquivalentTo(_options.Facets);
+ adapterRequest!.SearchFields.Should().BeEquivalentTo(_searchByKeywordCriteriaStub.SearchFields);
+ adapterRequest!.Facets.Should().BeEquivalentTo(_searchByKeywordCriteriaStub.Facets);
adapterRequest!.SearchFilterRequests.Should().BeEquivalentTo(request.FilterRequests);
}