Skip to content

Commit

Permalink
♻️ Rename Module to Feature (#35)
Browse files Browse the repository at this point in the history
Closes #26
  • Loading branch information
Hona authored Mar 20, 2024
1 parent b43d7a2 commit 2e179ff
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 40 deletions.
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);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace VerticalSliceArchitectureTemplate.Features.Todos;

public sealed class TodoModule : IModule
public sealed class TodoFeature : IFeature
{
public static void ConfigureServices(IServiceCollection services)
{
Expand Down
33 changes: 33 additions & 0 deletions src/VerticalSliceArchitectureTemplate/Host/FeatureDiscovery.cs
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 src/VerticalSliceArchitectureTemplate/Host/ModuleDiscovery.cs

This file was deleted.

2 changes: 1 addition & 1 deletion src/VerticalSliceArchitectureTemplate/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

builder.Services.AddExceptionHandler<ExceptionHandler.KnownExceptionsHandler>();

builder.Services.ConfigureModules(appAssembly);
builder.Services.ConfigureFeatures(appAssembly);

var app = builder.Build();

Expand Down

0 comments on commit 2e179ff

Please sign in to comment.