Skip to content

Commit

Permalink
Cl/service registration methods (#43)
Browse files Browse the repository at this point in the history
* add extension methods to register dependencies
  • Loading branch information
CathLass authored Sep 4, 2024
1 parent 3b40da1 commit d50d8a7
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Dfe.Data.SearchPrototype/Dfe.Data.SearchPrototype.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
<None Remove="Web\**" />
</ItemGroup>


<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="Common\Dfe.Data.SearchPrototype.Common.csproj" />
</ItemGroup>
Expand Down
35 changes: 35 additions & 0 deletions Dfe.Data.SearchPrototype/Infrastructure/DependencyRegistration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Azure.Search.Documents.Models;
using Azure;
using Dfe.Data.SearchPrototype.Common.Mappers;
using Dfe.Data.SearchPrototype.Infrastructure.Mappers;
using Dfe.Data.SearchPrototype.SearchForEstablishments;
using Dfe.Data.SearchPrototype.SearchForEstablishments.Models;
using Microsoft.Extensions.DependencyInjection;
using Azure.Search.Documents;
using Dfe.Data.SearchPrototype.Infrastructure.Options.Mappers;
using Dfe.Data.SearchPrototype.Infrastructure.Options;

namespace Dfe.Data.SearchPrototype.Infrastructure;

/// <summary>
/// Extension method which provides all the pre-registrations required to
/// access services to adapt the Dfe.Data.Common.Infrastructure.CognitiveSearch infrastructure
/// to SearchPrototype application layer
/// </summary>
public static class DependencyRegistration
{
/// <summary>
/// Register the necessary infrastucture adaptor services
/// </summary>
/// <param name="services"></param>
public static void AddCognitiveSearchAdaptorServices(this IServiceCollection services)
{
services.AddScoped(typeof(ISearchServiceAdapter), typeof(CognitiveSearchServiceAdapter<Establishment>));
services.AddSingleton(typeof(IMapper<Pageable<SearchResult<Establishment>>, EstablishmentResults>), typeof(PageableSearchResultsToEstablishmentResultsMapper));
services.AddSingleton<IMapper<SearchSettingsOptions, SearchOptions>, SearchOptionsToAzureOptionsMapper>();
services.AddSingleton<IMapper<Establishment, Address>, AzureSearchResultToAddressMapper>();
services.AddSingleton<IMapper<Establishment, SearchForEstablishments.Models.Establishment>, AzureSearchResultToEstablishmentMapper>();
services.AddScoped<ISearchOptionsFactory, SearchOptionsFactory>();
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using Dfe.Data.SearchPrototype.Common.CleanArchitecture.Application.UseCase;
using Microsoft.Extensions.DependencyInjection;

namespace Dfe.Data.SearchPrototype.SearchForEstablishments;

/// <summary>
/// Extension method which provides all the pre-registrations required to
/// use the SearchForEstablishments services
/// </summary>
public static class DependencyRegistration
{
/// <summary>
/// Register all the necessary SearchForEstablishments services
/// </summary>
/// <param name="services"></param>
public static void AddSearchForEstablishmentServices(this IServiceCollection services)
{
services.AddScoped<IUseCase<SearchByKeywordRequest, SearchByKeywordResponse>, SearchByKeywordUseCase>();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
namespace Dfe.Data.SearchPrototype.SearchForEstablishments.Models;

/// <summary>
/// Encapsulates the address details of an Establishment
/// </summary>
public class Address
{
/// <summary>
Expand Down

0 comments on commit d50d8a7

Please sign in to comment.