Skip to content

Commit

Permalink
remove opaque ObjectFactory nonsense in favour of ProjectPathResolver…
Browse files Browse the repository at this point in the history
…Factory
  • Loading branch information
rkm committed Oct 10, 2024
1 parent 20547c5 commit 9e318f2
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion data/microserviceConfigs/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CohortExtractorOptions:

AuditorType: "SmiServices.Microservices.CohortExtractor.Audit.NullAuditExtractions"
RequestFulfillerType: "SmiServices.Microservices.CohortExtractor.RequestFulfillers.FromCataloguesExtractionRequestFulfiller"
ProjectPathResolverType: "SmiServices.Microservices.CohortExtractor.ProjectPathResolvers.StudySeriesSOPProjectPathResolver"
ProjectPathResolverType: "StudySeriesSOPProjectPathResolver"
ExtractAnonRoutingKey: anon
ExtractIdentRoutingKey: ident
# Writes (Producer) to this exchange
Expand Down
2 changes: 1 addition & 1 deletion docs/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CohortExtractorOptions:

AuditorType: "Microservices.CohortExtractor.Audit.NullAuditExtractions"
RequestFulfillerType: "Microservices.CohortExtractor.Execution.RequestFulfillers.FromCataloguesExtractionRequestFulfiller"
ProjectPathResolverType: "Microservices.CohortExtractor.Execution.ProjectPathResolvers.StudySeriesSOPProjectPathResolver"
ProjectPathResolverType: "StudySeriesSOPProjectPathResolver"
ExtractAnonRoutingKey: anon
ExtractIdentRoutingKey: ident
# Writes (Producer) to this exchange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,7 @@ private void InitializeExtractionSources(IRDMPPlatformRepositoryServiceLocator r

_pathResolver = string.IsNullOrWhiteSpace(_consumerOptions.ProjectPathResolverType)
? new StudySeriesSOPProjectPathResolver(_fileSystem)
: ObjectFactory.CreateInstance<IProjectPathResolver>(
_consumerOptions.ProjectPathResolverType, typeof(IProjectPathResolver).Assembly, repositoryLocator);
: ProjectPathResolverFactory.Create(_consumerOptions.ProjectPathResolverType, _fileSystem);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.IO.Abstractions;

namespace SmiServices.Microservices.CohortExtractor.ProjectPathResolvers;
internal class ProjectPathResolverFactory
{
public static IProjectPathResolver Create(string projectPathResolverType, IFileSystem fileSystem)
{
return projectPathResolverType switch
{
"StudySeriesSOPProjectPathResolver" => new StudySeriesSOPProjectPathResolver(fileSystem),
"NoSuffixProjectPathResolver" => new NoSuffixProjectPathResolver(fileSystem),
"StudySeriesOriginalFilenameProjectPathResolver" => new StudySeriesOriginalFilenameProjectPathResolver(fileSystem),
_ => throw new NotImplementedException($"No case for IProjectPathResolver type '{projectPathResolverType}'"),
};
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using NUnit.Framework;
using SmiServices.Common.Helpers;
using SmiServices.Common.Messages.Extraction;
using SmiServices.Microservices.CohortExtractor.ProjectPathResolvers;
using SmiServices.Microservices.CohortExtractor.RequestFulfillers;
Expand Down Expand Up @@ -73,12 +72,5 @@ public void GetOutputPath_Extensions(string expectedOutput, string inputFile)

Assert.That(actualPath, Is.EqualTo(expectedPath));
}

[Test]
public void CanBeConstructedByReflection()
{
var instance = new MicroserviceObjectFactory().CreateInstance<IProjectPathResolver>("SmiServices.Microservices.CohortExtractor.ProjectPathResolvers.NoSuffixProjectPathResolver", typeof(IProjectPathResolver).Assembly, _fileSystem);
Assert.That(instance, Is.InstanceOf<NoSuffixProjectPathResolver>());
}
}
}
2 changes: 1 addition & 1 deletion tests/SmiServices.UnitTests/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ CohortExtractorOptions:

AuditorType: "SmiServices.Microservices.CohortExtractor.Audit.NullAuditExtractions"
RequestFulfillerType: "SmiServices.Microservices.CohortExtractor.RequestFulfillers.FromCataloguesExtractionRequestFulfiller"
ProjectPathResolverType: "SmiServices.Microservices.CohortExtractor.ProjectPathResolvers.StudySeriesSOPProjectPathResolver"
ProjectPathResolverType: "StudySeriesSOPProjectPathResolver"
ExtractAnonRoutingKey: anon
ExtractIdentRoutingKey: ident
# Writes (Producer) to this exchange
Expand Down

0 comments on commit 9e318f2

Please sign in to comment.