public static void CreateDispatcher(IServiceCollection services) { if (null != services) { INameResolver nameResolver = null; IOptions <EventSourcingOnAzureOptions> options = null; ILogger logger = null; var provider = services.BuildServiceProvider(); using (var scope = provider.CreateScope()) { nameResolver = scope.ServiceProvider.GetRequiredService <INameResolver>(); IConfiguration configuration = scope.ServiceProvider.GetRequiredService <IConfiguration> (); if (null != configuration) { EventSourcingOnAzureOptions optionConfig = new EventSourcingOnAzureOptions(configuration); options = Options.Create <EventSourcingOnAzureOptions>(optionConfig); if (null == nameResolver) { // make a default name resolver nameResolver = new NotificationDispatcherNameResolver(configuration); } } } if (null == options) { // make a default } NotificationDispatcher = new NotificationHelper(options, nameResolver, logger); } }
/// <summary> /// Create any static classes used to dispatch notifications /// </summary> /// <param name="services"></param> public static void CreateDispatchers(IServiceCollection services) { if (null != services) { INameResolver nameResolver = null; IOptions <EventSourcingOnAzureOptions> options = null; ILogger logger = null; IEventStreamSettings settings = null; var provider = services.BuildServiceProvider(); using (var scope = provider.CreateScope()) { nameResolver = scope.ServiceProvider.GetRequiredService <INameResolver>(); IConfiguration configuration = scope.ServiceProvider.GetRequiredService <IConfiguration> (); if (null != configuration) { EventSourcingOnAzureOptions optionConfig = new EventSourcingOnAzureOptions(configuration); options = Options.Create <EventSourcingOnAzureOptions>(optionConfig); if (null == nameResolver) { // make a default name resolver nameResolver = new NotificationDispatcherNameResolver(configuration); } } // Get the event stream settings to use settings = scope.ServiceProvider.GetRequiredService <IEventStreamSettings>(); } if (null == options) { // make a default set of options } // Add the default notification dispatchers if (NotificationDispatchers == null) { NotificationDispatchers = new ConcurrentDictionary <string, INotificationDispatcher>(); } EventGridNotificationDispatcher evDispatcher = new EventGridNotificationDispatcher(options, nameResolver, logger); if (evDispatcher != null) { NotificationDispatchers.TryAdd(evDispatcher.Name, evDispatcher); } QueueNotificationDispatcher quDispatch = new QueueNotificationDispatcher(options, settings, logger); if (quDispatch != null) { NotificationDispatchers.TryAdd(quDispatch.Name, quDispatch); } NullNotificationDispatcher nuDispatch = new NullNotificationDispatcher(); if (nuDispatch != null) { NotificationDispatchers.TryAdd(nuDispatch.Name, nuDispatch); } } }