-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #26
- Loading branch information
Showing
5 changed files
with
36 additions
and
40 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
...ectureTemplate/Common/Features/IModule.cs → ...ctureTemplate/Common/Features/IFeature.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
namespace VerticalSliceArchitectureTemplate.Common.Features; | ||
|
||
public interface IModule | ||
public interface IFeature | ||
{ | ||
static abstract void ConfigureServices(IServiceCollection services); | ||
} |
2 changes: 1 addition & 1 deletion
2
...tureTemplate/Features/Todos/TodoModule.cs → ...ureTemplate/Features/Todos/TodoFeature.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/VerticalSliceArchitectureTemplate/Host/FeatureDiscovery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using System.Reflection; | ||
|
||
namespace VerticalSliceArchitectureTemplate.Host; | ||
|
||
public static class FeatureDiscovery | ||
{ | ||
private static readonly Type ModuleType = typeof(IFeature); | ||
|
||
public static void ConfigureFeatures(this IServiceCollection services, params Assembly[] assemblies) | ||
{ | ||
if (assemblies.Length == 0) | ||
{ | ||
throw new ArgumentException("At least one assembly must be provided.", nameof(assemblies)); | ||
} | ||
|
||
var moduleTypes = GetFeatureTypes(assemblies); | ||
|
||
foreach (var type in moduleTypes) | ||
{ | ||
var method = GetConfigureServicesMethod(type); | ||
method?.Invoke(null, [services]); | ||
} | ||
} | ||
|
||
private static IEnumerable<Type> GetFeatureTypes(params Assembly[] assemblies) => | ||
assemblies.SelectMany(x => x.GetTypes()) | ||
.Where(x => ModuleType.IsAssignableFrom(x) && | ||
x is { IsInterface: false, IsAbstract: false }); | ||
|
||
private static MethodInfo? GetConfigureServicesMethod(Type type) => | ||
type.GetMethod(nameof(IFeature.ConfigureServices), | ||
BindingFlags.Static | BindingFlags.Public); | ||
} |
37 changes: 0 additions & 37 deletions
37
src/VerticalSliceArchitectureTemplate/Host/ModuleDiscovery.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters