Skip to content

Commit 40320c7

Browse files
committed
Add FromTypes methods to match other assembly selector naming convention, obsolete existing ones
1 parent d608097 commit 40320c7

File tree

5 files changed

+44
-21
lines changed

5 files changed

+44
-21
lines changed

src/Scrutor/ITypeSelector.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,28 @@ public interface ITypeSelector : IFluentInterface
1010
/// </summary>
1111
/// <param name="types">The types in which assemblies that should be scanned.</param>
1212
/// <exception cref="ArgumentNullException">If the <paramref name="types"/> argument is <c>null</c>.</exception>
13+
[Obsolete("This method has been marked obsolete and will be removed in the next major version. Use " + nameof(FromTypes) + " instead.")]
1314
IServiceTypeSelector AddTypes(params Type[] types);
1415

1516
/// <summary>
1617
/// Will scan the types <see cref="Type"/> in <paramref name="types"/>.
1718
/// </summary>
1819
/// <param name="types">The types in which assemblies that should be scanned.</param>
1920
/// <exception cref="ArgumentNullException">If the <paramref name="types"/> argument is <c>null</c>.</exception>
21+
IServiceTypeSelector FromTypes(params Type[] types);
22+
23+
/// <summary>
24+
/// Will scan the types <see cref="Type"/> in <paramref name="types"/>.
25+
/// </summary>
26+
/// <param name="types">The types in which assemblies that should be scanned.</param>
27+
/// <exception cref="ArgumentNullException">If the <paramref name="types"/> argument is <c>null</c>.</exception>
28+
[Obsolete("This method has been marked obsolete and will be removed in the next major version. Use " + nameof(FromTypes) + " instead.")]
2029
IServiceTypeSelector AddTypes(IEnumerable<Type> types);
21-
}
30+
31+
/// <summary>
32+
/// Will scan the types <see cref="Type"/> in <paramref name="types"/>.
33+
/// </summary>
34+
/// <param name="types">The types in which assemblies that should be scanned.</param>
35+
/// <exception cref="ArgumentNullException">If the <paramref name="types"/> argument is <c>null</c>.</exception>
36+
IServiceTypeSelector FromTypes(IEnumerable<Type> types);
37+
}

src/Scrutor/TypeSelectorExtensions.cs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,38 @@
1+
using System;
12
using JetBrains.Annotations;
23

34
namespace Scrutor;
45

56
[PublicAPI]
67
public static class TypeSelectorExtensions
78
{
8-
public static IServiceTypeSelector AddType<T>(this ITypeSelector selector)
9+
[Obsolete("This method has been marked obsolete and will be removed in the next major version. Use " + nameof(FromTypes) + " instead.")]
10+
public static IServiceTypeSelector AddType<T>(this ITypeSelector selector) => selector.FromType<T>();
11+
12+
public static IServiceTypeSelector FromType<T>(this ITypeSelector selector)
913
{
1014
Preconditions.NotNull(selector, nameof(selector));
1115

12-
return selector.AddTypes(typeof(T));
16+
return selector.FromTypes(typeof(T));
1317
}
1418

15-
public static IServiceTypeSelector AddTypes<T1, T2>(this ITypeSelector selector)
19+
[Obsolete("This method has been marked obsolete and will be removed in the next major version. Use " + nameof(FromTypes) + " instead.")]
20+
public static IServiceTypeSelector AddTypes<T1, T2>(this ITypeSelector selector) => selector.FromTypes<T1, T2>();
21+
22+
public static IServiceTypeSelector FromTypes<T1, T2>(this ITypeSelector selector)
1623
{
1724
Preconditions.NotNull(selector, nameof(selector));
1825

19-
return selector.AddTypes(typeof(T1), typeof(T2));
26+
return selector.FromTypes(typeof(T1), typeof(T2));
2027
}
2128

22-
public static IServiceTypeSelector AddTypes<T1, T2, T3>(this ITypeSelector selector)
29+
[Obsolete("This method has been marked obsolete and will be removed in the next major version. Use " + nameof(FromTypes) + " instead.")]
30+
public static IServiceTypeSelector AddTypes<T1, T2, T3>(this ITypeSelector selector) => selector.FromTypes<T1, T2, T3>();
31+
32+
public static IServiceTypeSelector FromTypes<T1, T2, T3>(this ITypeSelector selector)
2333
{
2434
Preconditions.NotNull(selector, nameof(selector));
2535

26-
return selector.AddTypes(typeof(T1), typeof(T2), typeof(T3));
36+
return selector.FromTypes(typeof(T1), typeof(T2), typeof(T3));
2737
}
2838
}

src/Scrutor/TypeSourceSelector.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -120,18 +120,15 @@ public IImplementationTypeSelector FromAssemblies(IEnumerable<Assembly> assembli
120120
return InternalFromAssemblies(assemblies);
121121
}
122122

123-
public IServiceTypeSelector AddTypes(params Type[] types)
124-
{
125-
Preconditions.NotNull(types, nameof(types));
123+
[Obsolete("This method has been marked obsolete and will be removed in the next major version. Use " + nameof(FromTypes) + " instead.")]
124+
public IServiceTypeSelector AddTypes(params Type[] types) => FromTypes(types);
126125

127-
var selector = new ImplementationTypeSelector(this, types);
126+
[Obsolete("This method has been marked obsolete and will be removed in the next major version. Use " + nameof(FromTypes) + " instead.")]
127+
public IServiceTypeSelector AddTypes(IEnumerable<Type> types) => FromTypes(types);
128128

129-
Selectors.Add(selector);
130-
131-
return selector.AddClasses();
132-
}
129+
public IServiceTypeSelector FromTypes(params Type[] types) => FromTypes(types.AsEnumerable());
133130

134-
public IServiceTypeSelector AddTypes(IEnumerable<Type> types)
131+
public IServiceTypeSelector FromTypes(IEnumerable<Type> types)
135132
{
136133
Preconditions.NotNull(types, nameof(types));
137134

@@ -188,4 +185,4 @@ private IImplementationTypeSelector AddSelector(IEnumerable<Type> types)
188185

189186
return selector;
190187
}
191-
}
188+
}

test/Scrutor.Tests/ScanningTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class ScanningTests : TestBase
1717
public void Scan_TheseTypes()
1818
{
1919
Collection.Scan(scan => scan
20-
.AddTypes<TransientService1, TransientService2>()
20+
.FromTypes<TransientService1, TransientService2>()
2121
.AsImplementedInterfaces(x => x != typeof(IOtherInheritance))
2222
.WithSingletonLifetime());
2323

@@ -383,7 +383,7 @@ public void ShouldRegisterOpenGenericTypes()
383383
};
384384

385385
Collection.Scan(scan => scan
386-
.AddTypes(genericTypes)
386+
.FromTypes(genericTypes)
387387
.AddClasses()
388388
.AsImplementedInterfaces());
389389

@@ -402,7 +402,7 @@ public void ShouldRegisterOpenGenericTypes()
402402
[Fact]
403403
public void ShouldNotIncludeCompilerGeneratedTypes()
404404
{
405-
Assert.Empty(Collection.Scan(scan => scan.AddType<CompilerGenerated>()));
405+
Assert.Empty(Collection.Scan(scan => scan.FromType<CompilerGenerated>()));
406406
}
407407

408408
[Fact]

test/Scrutor.Tests/Scrutor.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<ItemGroup>
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.0.0" />
1313
<PackageReference Include="xunit" Version="2.4.1" />
14-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All"/>
14+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3" PrivateAssets="All" />
1515
<PackageReference Include="coverlet.collector" Version="3.1.2" PrivateAssets="All" />
1616
</ItemGroup>
1717

0 commit comments

Comments
 (0)