-
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.
var logs = services.RegisterGenericEventRunner( //"var logs = " is optional - see note below.
Assembly.GetAssembly(typeof(ReviewAddedHandler)),
Assembly.GetAssembly(typeof(CosmasUpdaterHandler))
);NOTES
- If you don't provide any assemblies, then it scans the assembly that called the
RegisterGenericEventRunnerextension method. - The logs are optional, but the provide a list of what it found and registered. That's useful for debugging issues.
This is very similar to the non-config 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);
var logs = services.RegisterGenericEventRunner( //"var logs = " is optional - see note above.
eventConfig, //Adds configuration to GenericEventRunner
Assembly.GetAssembly(typeof(ReviewAddedHandler)),
Assembly.GetAssembly(typeof(CosmasUpdaterHandler))
);