diff --git a/src/Scrutor/IImplementationTypeFilter.cs b/src/Scrutor/IImplementationTypeFilter.cs index c5b14ef8..6720af0f 100644 --- a/src/Scrutor/IImplementationTypeFilter.cs +++ b/src/Scrutor/IImplementationTypeFilter.cs @@ -155,4 +155,11 @@ public interface IImplementationTypeFilter : IFluentInterface /// The predicate to match types. /// If the argument is null. IImplementationTypeFilter Where(Func predicate); -} \ No newline at end of file + + /// + /// Will transform the types using the specified . + /// + /// A transform function to apply to each element. + /// If the argument is null. + IImplementationTypeFilter Select(Func selector); +} diff --git a/src/Scrutor/ImplementationTypeFilter.cs b/src/Scrutor/ImplementationTypeFilter.cs index 54e5af61..22fb9d68 100644 --- a/src/Scrutor/ImplementationTypeFilter.cs +++ b/src/Scrutor/ImplementationTypeFilter.cs @@ -154,4 +154,12 @@ public IImplementationTypeFilter Where(Func predicate) Types = Types.Where(predicate); return this; } -} \ No newline at end of file + + public IImplementationTypeFilter Select(Func selector) + { + Preconditions.NotNull(selector, nameof(selector)); + + Types = Types.Select(selector); + return this; + } +} diff --git a/test/Scrutor.Tests/ScanningTests.cs b/test/Scrutor.Tests/ScanningTests.cs index 541f198f..82be47b2 100644 --- a/test/Scrutor.Tests/ScanningTests.cs +++ b/test/Scrutor.Tests/ScanningTests.cs @@ -428,6 +428,20 @@ public void ShouldRegisterOpenGenericTypes() Assert.Null(provider.GetService>()); } + [Fact] + public void ShouldRegisterPartiallyOpenGenericTypesUsingSelect() + { + Collection.Scan(scan => scan.FromAssemblyOf() + .AddClasses(classes => + classes.AssignableTo().Select(x => typeof(ProcessDtoCommandHandler<>).MakeGenericType(x))) + .AsImplementedInterfaces()); + + var provider = Collection.BuildServiceProvider(); + + Assert.NotNull(provider.GetService>>()); + Assert.NotNull(provider.GetService>>()); + } + [Fact] public void ShouldNotIncludeCompilerGeneratedTypes() { @@ -556,6 +570,17 @@ public class QueryHandler : IQueryHandler { } public interface IOpenGeneric : IOtherInheritance { } public class OpenGeneric : IOpenGeneric { } + + public interface ICommandHandler { } + + public class ProcessDto where T : IDto { } + public class ProcessDtoCommandHandler : ICommandHandler> where T : IDto { } + + public interface IDto {} + + public record FooDto : IDto {} + + public record BarDto : IDto {} public interface IPartiallyClosedGeneric { }