22 lines
698 B
C#
22 lines
698 B
C#
using Medusa.Core.Handlers;
|
|
using Medusa.Core.Services;
|
|
using System.Reflection;
|
|
|
|
namespace Medusa.Core.Extensions
|
|
{
|
|
public static class ApplicationBuilderExtensions
|
|
{
|
|
public static IApplicationBuilder UseHandlers(this IApplicationBuilder app)
|
|
{
|
|
var handlerService = app.ApplicationServices.GetRequiredService<IHandlerService>();
|
|
|
|
var assembly = Assembly.GetEntryAssembly() ?? throw new InvalidOperationException("Could not find entry assembly.");
|
|
var types = assembly.GetTypes().Where(t => t.GetInterfaces().Contains(typeof(IHandler)));
|
|
|
|
handlerService.Handlers.AddRange(types);
|
|
|
|
return app;
|
|
}
|
|
}
|
|
}
|