public static IServiceCollection AddEventHandler(this IServiceCollection services, Action <EventhandlerJsonFile> setupAction) { if (setupAction == null) { throw new ArgumentNullException(nameof(setupAction), $"{nameof(setupAction)} cannot be null."); } var options = new EventhandlerJsonFile(); setupAction.Invoke(options); ConfigureEventhandlerOptions(services, options); RegisterServices(services); return(services); }
private static void ConfigureEventhandlerOptions(IServiceCollection services, EventhandlerJsonFile options) { ValidateMandatoryField(options.FileName, nameof(options.FileName)); ValidateMandatoryField(options.Section, nameof(options.Section)); var builder = new ConfigurationBuilder().AddJsonFile(options.FileName); var config = builder.Build(); var section = config.GetSection(options.Section); services.Configure <EventhandlerOptions>(section); }