public void AddManager(string publisherName, Action <NotificationPublisherOptions> settings) { if (this.publisherManagers.ContainsKey(publisherName)) { return; } publisherManagers.Add(publisherName, () => { NotificationPublisherOptions options = new NotificationPublisherOptions(new NotificationRoutesTable()); settings(options); RedisConnection connection = ServiceProvider.GetRequiredService <IRedisSettingsProvider>().GetConnectionSettings(); NotificationEvents notificationEvents = new NoopNotificationEvents(); if (!(options.NotificationEventsType is null)) { notificationEvents = (NotificationEvents)ActivatorUtilities.CreateInstance(ServiceProvider, options.NotificationEventsType); } RedisConnectionManager connectionManager = new RedisConnectionManager(connection, notificationEvents); RedisManager redisManager = new RedisManager(connectionManager, notificationEvents); if (options.KeyBuilderBuilderType is null) { throw new Exception("You must define a key builder in the extension settings"); } NotificationKeyBuilder keyBuilder = (NotificationKeyBuilder)ActivatorUtilities.CreateInstance(ServiceProvider, options.KeyBuilderBuilderType); return(new NotificationPublisherClient(keyBuilder, redisManager, options)); });
public void AddManager <THub, THubActions>(Action <NotificationOptions> settings) where THub : Hub <THubActions> where THubActions : class { if (!subscribersManagers.ContainsKey(typeof(THubActions))) { NotificationOptions options = new NotificationOptions(new NotificationRoutesTable(), new NotificationControllersTable()); settings(options); if (options.KeyBuilderBuilderType is null) { throw new Exception("You must define a key builder in the extension settings"); } NotificationKeyBuilder keyBuilder = (NotificationKeyBuilder)ActivatorUtilities.CreateInstance(ServiceProvider, options.KeyBuilderBuilderType); NotificationEvents notificationEvents = new NoopNotificationEvents(); if (!(options.NotificationEventsType is null)) { notificationEvents = (NotificationEvents)ActivatorUtilities.CreateInstance(ServiceProvider, options.NotificationEventsType); } RedisConnection connection = ServiceProvider.GetRequiredService <IRedisSettingsProvider>().GetConnectionSettings(); RedisConnectionManager connectionManager = new RedisConnectionManager(connection, notificationEvents); RedisManager redisManager = new RedisManager(connectionManager, notificationEvents); NotificationPubSubManager <THub, THubActions> subManager = new NotificationPubSubManager <THub, THubActions>(ServiceProvider, keyBuilder, redisManager, options); subscribersManagers.Add(typeof(THubActions), subManager); } // do not throw exception. This method must be idemponent (no gains in throwing an exception) }