-
Notifications
You must be signed in to change notification settings - Fork 12
Setup: App startup
When your application starts EFCore.GenericEventRunner needs to find and register your event handlers and its EventRunner class with NET Core dependency injection (DI) provider. You tell the method which assembles in your application and it then scans each assembles for event handlers and registers then with the DI provider.
There are two options, one without extra configuration and one with configuration.
You provider a series of assemblies to scan. The easier way to do this is use Assembly.GetAssembly(<Type>). e.g.
services.RegisterGenericEventRunner(
Assembly.GetAssembly(typeof(ReviewAddedHandler)),
Assembly.GetAssembly(typeof(CosmasUpdaterHandler))
);NOTE: If you don't provide any assemblies, then it scans the assembly that called the RegisterGenericEventRunner extension method.
This is very similar to the non-cofig version, but the first parameter should now be of the type IGenericEventRunnerConfig. Here is an example of using the GenericEventRunnerConfig class to register a exception handler for a class called BookDbContext.
var eventConfig = new GenericEventRunnerConfig();
eventConfig.RegisterSaveChangesExceptionHandler<BookDbContext>(
BookWithEventsConcurrencyHandler.HandleCacheValuesConcurrency);
services.RegisterGenericEventRunner(
eventConfig, //Adds configuration to GenericEventRunner
Assembly.GetAssembly(typeof(ReviewAddedHandler)),
Assembly.GetAssembly(typeof(CosmasUpdaterHandler))
);