/// <summary> /// Adds a plugin that invokes hub methods on an Azure SignalR Service when events are published. /// </summary> /// <param name="pluginOptions">The <see cref="EventsContext"/> options.</param> /// <param name="configuration"> /// A configuration section with the same structure of the <see cref="AzureSignalRServiceOptions"/> type. /// </param> /// <returns>The same instance of <see cref="IFluentEventsPluginOptions"/> for chaining.</returns> public static IFluentEventsPluginOptions UseAzureSignalRService( this IFluentEventsPluginOptions pluginOptions, IConfiguration configuration ) { return(pluginOptions.UseAzureSignalRService(configuration, null)); }
/// <summary> /// Adds a plugin that receives events published from other instances of the application /// using an Azure Service Bus topic. /// </summary> /// <remarks> /// The management connection string is required to dynamically create topic subscriptions. /// </remarks> /// <param name="pluginOptions">The <see cref="EventsContext"/> options.</param> /// <param name="configureOptions"> /// An <see cref="Action"/> to configure the <see cref="AzureTopicEventReceiverOptions"/> for the receiving plugin. /// </param> /// <returns>The same instance of <see cref="IFluentEventsPluginOptions"/> for chaining.</returns> public static IFluentEventsPluginOptions UseAzureTopicEventReceiver( this IFluentEventsPluginOptions pluginOptions, Action <AzureTopicEventReceiverOptions> configureOptions ) { if (pluginOptions == null) { throw new ArgumentNullException(nameof(pluginOptions)); } pluginOptions.AddPlugin(new AzureTopicEventReceiverPlugin(configureOptions)); return(pluginOptions); }
/// <summary> /// Adds a plugin that sends publishes events to different instances of the application /// using an Azure Service Bus topic. /// </summary> /// <param name="pluginOptions">The <see cref="EventsContext"/> options.</param> /// <param name="configuration"> /// A configuration section with the same structure of the <see cref="AzureTopicEventSenderOptions"/> type. /// </param> /// <returns>The same instance of <see cref="IFluentEventsPluginOptions"/> for chaining.</returns> public static IFluentEventsPluginOptions UseAzureTopicEventSender( this IFluentEventsPluginOptions pluginOptions, IConfiguration configuration ) { if (pluginOptions == null) { throw new ArgumentNullException(nameof(pluginOptions)); } pluginOptions.AddPlugin(new AzureTopicEventSenderPlugin(configuration)); return(pluginOptions); }
/// <summary> /// Adds a plugin that attaches the entities tracked by a <see cref="DbContext"/> /// to the <see cref="EventsContext"/> automatically. /// </summary> /// <remarks> /// In order to automatically attach the entities the <see cref="DbContext"/> must be attached /// to the <see cref="EventsContext"/> manually or by using the /// <see cref="FluentEvents.ServiceCollectionExtensions.AddWithEventsAttachedTo{TEventsContext}"/> /// method. (See example) /// </remarks> /// <example> /// services.AddWithEventsAttachedTo<SampleEventsContext>(() => { /// services.AddScoped<MyDbContext>(); /// }); /// /// services.AddEventsContext<SampleEventsContext>(options => { /// options.AttachToDbContextEntities<MyDbContext>(); /// }); /// </example> /// <param name="pluginOptions">The <see cref="EventsContext"/> options.</param> /// <typeparam name="TDbContext">The type of the <see cref="DbContext"/>.</typeparam> /// <returns>The same instance of <see cref="IFluentEventsPluginOptions"/> for chaining.</returns> public static IFluentEventsPluginOptions AttachToDbContextEntities <TDbContext>( this IFluentEventsPluginOptions pluginOptions ) where TDbContext : DbContext { if (pluginOptions == null) { throw new ArgumentNullException(nameof(pluginOptions)); } pluginOptions.AddPlugin(new EntityFrameworkPlugin <TDbContext>()); return(pluginOptions); }
public ServiceProvider BuildServiceProvider(IEventsContext eventsContext, IFluentEventsPluginOptions options) { Func <IServiceProvider, object> GetLoggerFactory() => x => _rootAppServiceProvider.GetService <ILoggerFactory>() ?? new LoggerFactory(x.GetService <IEnumerable <ILoggerProvider> >()); var services = new ServiceCollection(); services.AddLogging(); services.Replace(new ServiceDescriptor( typeof(ILoggerFactory), GetLoggerFactory(), ServiceLifetime.Singleton )); services.AddSingleton(_rootAppServiceProvider); services.AddSingleton(eventsContext); services.AddSingleton <PipelinesBuilder>(); services.AddSingleton <SubscriptionsBuilder>(); services.AddSingleton <IEventsQueuesService, EventsQueuesService>(); services.AddSingleton <IScopedSubscriptionsService, ScopedSubscriptionsService>(); services.AddSingleton <IRoutingService, RoutingService>(); services.AddSingleton <IForwardingService, ForwardingService>(); services.AddSingleton <IEventsQueueNamesService, EventsQueueNamesService>(); services.AddSingleton <IEventsSerializationService, JsonEventsSerializationService>(); services.AddSingleton <IGlobalSubscriptionsService, GlobalSubscriptionsService>(); services.AddSingleton <ISourceModelsService, SourceModelsService>(); services.AddSingleton <IPublishingService, PublishingService>(); services.AddSingleton <IEventReceiversService, EventReceiversService>(); services.AddSingleton <IAttachingService, AttachingService>(); services.AddSingleton <ISubscriptionsMatchingService, SubscriptionsMatchingService>(); services.AddSingleton <IPipelinesService, PipelinesService>(); services.AddSingleton <EnqueuePipelineModule>(); services.AddSingleton <FilterPipelineModule>(); services.AddSingleton <GlobalPublishPipelineModule>(); services.AddSingleton <ScopedPublishPipelineModule>(); services.AddSingleton <ProjectionPipelineModule>(); services.AddSingleton <EventReceiversHostedService>(); foreach (var plugin in options.Plugins) { plugin.ApplyServices(services); } return(services.BuildServiceProvider()); }
/// <summary> /// Adds a plugin that invokes hub methods on an Azure SignalR Service when events are published. /// </summary> /// <param name="pluginOptions">The <see cref="EventsContext"/> options.</param> /// <param name="configuration"> /// A configuration section with the same structure of the <see cref="AzureSignalRServiceOptions"/> type. /// </param> /// <param name="httpClientBuilder"> /// An <see cref="Action{T}"/> to further configure the <see cref="HttpClient"/> used to make requests to /// the Azure SignalR Service. /// </param> /// <returns>The same instance of <see cref="IFluentEventsPluginOptions"/> for chaining.</returns> public static IFluentEventsPluginOptions UseAzureSignalRService( this IFluentEventsPluginOptions pluginOptions, IConfiguration configuration, Action <IHttpClientBuilder> httpClientBuilder ) { if (pluginOptions == null) { throw new ArgumentNullException(nameof(pluginOptions)); } if (configuration == null) { throw new ArgumentNullException(nameof(configuration)); } pluginOptions.AddPlugin(new AzureSignalRPlugin(configuration, httpClientBuilder)); return(pluginOptions); }