That being said, there are ways to auto register all event listener classes which could make things easier (but that would be a new feature request 😉)
Inspired by your insight, I decided to propose another API for auto-configuring event listeners:
public void ConfigureServices(IServiceCollection services)
{
services.AddEventsFromAssembly<Program>();
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseCoravelEvents();
}
When AddEventsFromAssembly is invoked, the method will scan the Assembly of that class for all IEvent and all IListener<> classes. Then those classes will be auto-registered into the Dependency Injection.
In addition, Coravel should automatically perform Register and Subscribe for all corresponding events and listeners based on the IListener<> generic type parameter.
Describe the solution you'd like
Continuing discussion from https://github.com/jamesmh/coravel/issues/142
Inspired by your insight, I decided to propose another API for auto-configuring event listeners:
When
AddEventsFromAssembly
is invoked, the method will scan the Assembly of that class for allIEvent
and allIListener<>
classes. Then those classes will be auto-registered into the Dependency Injection.In addition, Coravel should automatically perform
Register
andSubscribe
for all corresponding events and listeners based on theIListener<>
generic type parameter.Describe alternatives you've considered
Feature not yet available in Coravel.