/// <summary> /// Registers <see cref="QueuedHostedService{IWebHookNotification}"/> as the default <see cref="IWebHookSender"/>, allowing for a synchronous treatment of <see cref="IWebHookWorkItem"/> /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder ProcessWebHookWorkItemsUsingLocalQueue(this IHarpoonBuilder harpoon) { harpoon.Services.TryAddSingleton <IWebHookSender, BackgroundSender>(); harpoon.Services.TryAddSingleton <BackgroundQueue <IWebHookWorkItem> >(); harpoon.Services.AddHostedService <QueuedHostedService <IWebHookWorkItem> >(); return(harpoon); }
/// <summary> /// Registers <see cref="QueuedHostedService{IWebHookNotification}"/> as the default <see cref="IWebHookService"/>, allowing for a background treatment of <see cref="IWebHookNotification"/> /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder ProcessNotificationsUsingLocalQueue(this IHarpoonBuilder harpoon) { harpoon.Services.TryAddSingleton <IWebHookService, DefaultWebHookService>(); harpoon.Services.TryAddSingleton <BackgroundQueue <IWebHookNotification> >(); harpoon.Services.AddHostedService <QueuedHostedService <IWebHookNotification> >(); return(harpoon); }
/// <summary> /// Registers every services allowing for a pipeline to treat webhooks via a messaging service, while allowing sender retry policy configuration /// Some configuration that require a <see cref="IServiceCollectionConfigurator"/> and/or a <see cref="IBusFactoryConfigurator"/> might still be needed. /// </summary> /// <param name="harpoon"></param> /// <param name="senderPolicy"></param> /// <returns></returns> public static IServiceCollection UseAllMassTransitDefaults(this IHarpoonBuilder harpoon, Action <IHttpClientBuilder> senderPolicy) { return(harpoon.SendNotificationsUsingMassTransit() .UseDefaultNotificationProcessor() .SendWebHookWorkItemsUsingMassTransit() .UseDefaultWebHookWorkItemProcessor(senderPolicy) .Services); }
/// <summary> /// Registers <see cref="WebHookStore{TContext}"/> as <see cref="IWebHookStore"/> and <see cref="WebHookRegistrationStore{TContext}"/> as <see cref="IWebHookRegistrationStore"/>. /// TWebHookTriggerProvider needs to be configured. /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder RegisterWebHooksUsingEfStorage <TContext>(this IHarpoonBuilder harpoon) where TContext : DbContext, IRegistrationsContext { harpoon.Services.TryAddScoped <IPrincipalIdGetter, DefaultPrincipalIdGetter>(); harpoon.Services.TryAddScoped <IWebHookStore, WebHookStore <TContext> >(); harpoon.Services.TryAddScoped <IWebHookRegistrationStore, WebHookRegistrationStore <TContext> >(); return(harpoon); }
/// <summary> /// Registers <see cref="DefaultSecretProtector"/> as <see cref="ISecretProtector"/> /// </summary> /// <param name="harpoon"></param> /// <param name="dataProtection"></param> /// <param name="setupAction"></param> /// <returns></returns> public static IHarpoonBuilder UseDefaultDataProtection(this IHarpoonBuilder harpoon, Action <IDataProtectionBuilder> dataProtection, Action <DataProtectionOptions> setupAction) { if (dataProtection == null) { throw new ArgumentNullException("Data protection configuration is required.", nameof(dataProtection)); } harpoon.Services.TryAddScoped <ISecretProtector, DefaultSecretProtector>(); dataProtection(harpoon.Services.AddDataProtection(setupAction)); return(harpoon); }
/// <summary> /// Registers <see cref="WebHookStore{TContext}"/> as <see cref="IWebHookStore"/> and <see cref="WebHookRegistrationStore{TContext}"/> as <see cref="IWebHookRegistrationStore"/>. /// TWebHookTriggerProvider needs to be configured. /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="harpoon"></param> /// <param name="validatorPolicy"></param> /// <returns></returns> public static IHarpoonBuilder RegisterWebHooksUsingEfStorage <TContext>(this IHarpoonBuilder harpoon, Action <IHttpClientBuilder> validatorPolicy) where TContext : DbContext, IRegistrationsContext { harpoon.Services.TryAddScoped <IPrincipalIdGetter, DefaultPrincipalIdGetter>(); harpoon.Services.TryAddSingleton <IWebHookMatcher, DefaultWebHookMatcher>(); harpoon.Services.TryAddScoped <IWebHookStore, WebHookStore <TContext> >(); harpoon.Services.TryAddScoped <IWebHookRegistrationStore, WebHookRegistrationStore <TContext> >(); harpoon.UseDefaultValidator(validatorPolicy); return(harpoon); }
/// <summary> /// Registers services to use the default <see cref="IWebHookValidator"/> implementation. Necessary to use default controllers. /// </summary> /// <param name="harpoon"></param> /// <param name="validatorPolicy"></param> /// <returns></returns> public static IHarpoonBuilder UseDefaultValidator(this IHarpoonBuilder harpoon, Action <IHttpClientBuilder> validatorPolicy) { if (validatorPolicy == null) { throw new ArgumentNullException(nameof(validatorPolicy)); } harpoon.Services.TryAddScoped <IWebHookValidator, DefaultWebHookValidator>(); var builder = harpoon.Services.AddHttpClient <IWebHookValidator, DefaultWebHookValidator>(); validatorPolicy(builder); return(harpoon); }
/// <summary> /// Registers services to use <see cref="DefaultWebHookSender"/> as the default <see cref="IQueuedProcessor{IWebHookWorkItem}"/>. /// </summary> /// <param name="harpoon"></param> /// <param name="senderPolicy">This parameter lets you define your retry policy</param> /// <returns></returns> public static IHarpoonBuilder UseDefaultWebHookWorkItemProcessor(this IHarpoonBuilder harpoon, Action <IHttpClientBuilder> senderPolicy) { if (senderPolicy == null) { throw new ArgumentNullException(nameof(senderPolicy)); } harpoon.Services.TryAddSingleton <ISignatureService, DefaultSignatureService>(); harpoon.Services.TryAddScoped <IQueuedProcessor <IWebHookWorkItem>, DefaultWebHookSender>(); var builder = harpoon.Services.AddHttpClient <IQueuedProcessor <IWebHookWorkItem>, DefaultWebHookSender>(); senderPolicy(builder); return(harpoon); }
/// <summary> /// Registers <see cref="WebHookStore{TContext}"/> as <see cref="IWebHookStore"/> and <see cref="WebHookRegistrationStore{TContext}"/> as <see cref="IWebHookRegistrationStore"/>. /// TWebHookTriggerProvider needs to be configured. /// </summary> /// <param name="harpoon"></param> /// <param name="connectionString"></param> /// <param name="databaseName"></param> /// <returns></returns> public static IHarpoonBuilder RegisterWebHooksUsingMongoStorage(this IHarpoonBuilder harpoon, string connectionString, string databaseName) { harpoon.Services.TryAddScoped <IPrincipalIdGetter, DefaultPrincipalIdGetter>(); harpoon.Services.TryAddScoped <IWebHookStore, WebHookStore>(); harpoon.Services.TryAddScoped <IWebHookRegistrationStore, WebHookRegistrationStore>(); harpoon.Services.TryAddSingleton <IMongoClient>(provider => new MongoClient(connectionString)); harpoon.Services.TryAddSingleton <IMongoDatabase>(provider => provider.GetRequiredService <IMongoClient>().GetDatabase(databaseName)); harpoon.Services.TryAddScoped <IMongoContext <WebHook>, WebHookRepository>(); harpoon.Services.TryAddScoped <IMongoContext <WebHookFilter>, WebHookFilterRepository>(); harpoon.Services.TryAddScoped <IMongoContext <WebHookLog>, WebHookLogRepository>(); harpoon.Services.TryAddScoped <IMongoContext <WebHookNotification>, WebHookNotificationRepository>(); return(harpoon); }
/// <summary> /// Registers <see cref="WebHookStore{TContext}"/> as <see cref="IWebHookStore"/> and <see cref="WebHookRegistrationStore{TContext}"/> as <see cref="IWebHookRegistrationStore"/>. /// TWebHookTriggerProvider is registered as singleton /// </summary> /// <typeparam name="TContext"></typeparam> /// <typeparam name="TWebHookTriggerProvider"></typeparam> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder RegisterWebHooksUsingMongoStorage <TWebHookTriggerProvider>(this IHarpoonBuilder harpoon, string connectionString, string databaseName) where TWebHookTriggerProvider : class, IWebHookTriggerProvider { harpoon.Services.TryAddSingleton <IWebHookTriggerProvider, TWebHookTriggerProvider>(); return(harpoon.RegisterWebHooksUsingMongoStorage(connectionString, databaseName)); }
/// <summary> /// Registers <see cref="MongoNotificationProcessor"/> as the default <see cref="IWebHookService"/>, allowing for a synchronous treatment of <see cref="IWebHookNotification"/> /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder ProcessNotificationsSynchronouslyUsingMongoDefault <TContext>(this IHarpoonBuilder harpoon) { harpoon.Services.TryAddScoped <IWebHookService, MongoNotificationProcessor>(); return(harpoon); }
/// <summary> /// Registers <see cref="MongoNotificationProcessor"/> as the default <see cref="IQueuedProcessor{IWebHookNotification}"/>. /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder UseDefaultMongoNotificationProcessor <TContext>(this IHarpoonBuilder harpoon) { harpoon.Services.TryAddScoped <IQueuedProcessor <IWebHookNotification>, MongoNotificationProcessor>(); return(harpoon); }
/// <summary> /// Registers services to use <see cref="EFWebHookSender{TContext}"/> as the default <see cref="IQueuedProcessor{IWebHookWorkItem}"/>. /// To setup your own retry policy, use the second method signature. /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder UseDefaultEFWebHookWorkItemProcessor <TContext>(this IHarpoonBuilder harpoon) where TContext : DbContext, IRegistrationsContext => harpoon.UseDefaultEFWebHookWorkItemProcessor <TContext>(b => { });
/// <summary> /// Registers <see cref="DefaultNotificationProcessor"/> as the default <see cref="IWebHookService"/>, allowing for a synchronous treatment of <see cref="IWebHookNotification"/> /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder ProcessNotificationsSynchronously(this IHarpoonBuilder harpoon) { harpoon.Services.TryAddScoped <IWebHookService, DefaultNotificationProcessor>(); return(harpoon); }
/// <summary> /// Registers every services allowing for a synchronous pipeline to treat webhooks locally, while allowing sender retry policy configuration /// </summary> /// <param name="harpoon"></param> /// <param name="senderPolicy"></param> /// <returns></returns> public static IServiceCollection UseAllSynchronousDefaults(this IHarpoonBuilder harpoon, Action <IHttpClientBuilder> senderPolicy) => harpoon.ProcessNotificationsSynchronously() .UseDefaultNotificationProcessor() .ProcessWebHookWorkItemSynchronously() .UseDefaultWebHookWorkItemProcessor(senderPolicy) .Services;
/// <summary> /// Registers <see cref="PublisherService"/> as the default <see cref="IWebHookSender"/>, allowing for a treatment of <see cref="IWebHookWorkItem"/> via messaging service /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder SendWebHookWorkItemsUsingMassTransit(this IHarpoonBuilder harpoon) { harpoon.Services.AddSingleton <IWebHookSender, PublisherService>(); return(harpoon); }
/// <summary> /// Registers <see cref="WebHookStore{TContext}"/> as <see cref="IWebHookStore"/> and <see cref="WebHookRegistrationStore{TContext}"/> as <see cref="IWebHookRegistrationStore"/>. /// TWebHookTriggerProvider needs to be configured. /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder RegisterWebHooksUsingEfStorage <TContext>(this IHarpoonBuilder harpoon) where TContext : DbContext, IRegistrationsContext => harpoon.RegisterWebHooksUsingEfStorage <TContext>(b => { });
/// <summary> /// Registers <see cref="WebHookStore{TContext}"/> as <see cref="IWebHookStore"/> and <see cref="WebHookRegistrationStore{TContext}"/> as <see cref="IWebHookRegistrationStore"/>. /// TWebHookTriggerProvider is registered as singleton /// </summary> /// <typeparam name="TContext"></typeparam> /// <typeparam name="TWebHookTriggerProvider"></typeparam> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder RegisterWebHooksUsingEfStorage <TContext, TWebHookTriggerProvider>(this IHarpoonBuilder harpoon) where TContext : DbContext, IRegistrationsContext where TWebHookTriggerProvider : class, IWebHookTriggerProvider => harpoon.RegisterWebHooksUsingEfStorage <TContext, TWebHookTriggerProvider>(b => { });
/// <summary> /// Registers services to use <see cref="DefaultWebHookSender"/> as the default <see cref="IQueuedProcessor{IWebHookWorkItem}"/>. /// To setup your own retry policy, use the second method signature. /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder UseDefaultWebHookWorkItemProcessor(this IHarpoonBuilder harpoon) => harpoon.UseDefaultWebHookWorkItemProcessor(b => { });
/// <summary> /// Registers every services allowing for an asynchronous pipeline to treat webhooks locally, using background services, while allowing sender retry policy configuration /// </summary> /// <param name="harpoon"></param> /// <param name="senderPolicy"></param> /// <returns></returns> public static IServiceCollection UseAllLocalDefaults(this IHarpoonBuilder harpoon, Action <IHttpClientBuilder> senderPolicy) => harpoon.ProcessNotificationsUsingLocalQueue() .UseDefaultNotificationProcessor() .ProcessWebHookWorkItemsUsingLocalQueue() .UseDefaultWebHookWorkItemProcessor(senderPolicy) .Services;
/// <summary> /// Registers every services allowing for an asynchronous pipeline to treat webhooks locally, using background services. /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IServiceCollection UseAllLocalDefaults(this IHarpoonBuilder harpoon) => harpoon.UseAllLocalDefaults(b => { });
/// <summary> /// Registers every services allowing for a synchronous pipeline to treat webhooks locally. /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IServiceCollection UseAllSynchronousDefaults(this IHarpoonBuilder harpoon) => harpoon.UseAllSynchronousDefaults(b => { });
/// <summary> /// Registers every services allowing for a pipeline to treat webhooks via a messaging service. /// Some configuration that require a <see cref="IServiceCollectionConfigurator"/> and/or a <see cref="IBusFactoryConfigurator"/> might still be needed. /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IServiceCollection UseAllMassTransitDefaults(this IHarpoonBuilder harpoon) => harpoon.UseAllMassTransitDefaults(b => { });
/// <summary> /// Registers <see cref="WebHookStore{TContext}"/> as <see cref="IWebHookStore"/> and <see cref="WebHookRegistrationStore{TContext}"/> as <see cref="IWebHookRegistrationStore"/>. /// TWebHookTriggerProvider is registered as singleton /// </summary> /// <typeparam name="TContext"></typeparam> /// <typeparam name="TWebHookTriggerProvider"></typeparam> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder RegisterWebHooksUsingEfStorage <TContext, TWebHookTriggerProvider>(this IHarpoonBuilder harpoon) where TContext : DbContext, IRegistrationsContext where TWebHookTriggerProvider : class, IWebHookTriggerProvider { harpoon.Services.TryAddSingleton <IWebHookTriggerProvider, TWebHookTriggerProvider>(); return(harpoon.RegisterWebHooksUsingEfStorage <TContext>()); }
/// <summary> /// Registers <see cref="PublisherService"/> as the default <see cref="IWebHookService"/>, allowing for a treatment of <see cref="IWebHookNotification"/> via messaging service /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder SendNotificationsUsingMassTransit(this IHarpoonBuilder harpoon) { harpoon.Services.AddSingleton <IWebHookService, PublisherService>(); return(harpoon); }
/// <summary> /// Registers <see cref="IQueuedProcessor{IWebHookWorkItem}"/> as the default <see cref="IWebHookSender"/>, allowing for a synchronous treatment of <see cref="IWebHookWorkItem"/> /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder ProcessWebHookWorkItemSynchronously(this IHarpoonBuilder harpoon) { harpoon.Services.TryAddScoped(p => p.GetRequiredService <IQueuedProcessor <IWebHookWorkItem> >() as IWebHookSender); return(harpoon); }
/// <summary> /// Registers services to use the default <see cref="IWebHookValidator"/> implementation. Necessary to use default controllers. /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder UseDefaultValidator(this IHarpoonBuilder harpoon) => harpoon.UseDefaultValidator(b => { });
/// <summary> /// Registers <see cref="EFNotificationProcessor{TContext}"/> as the default <see cref="IQueuedProcessor{IWebHookNotification}"/>. /// </summary> /// <typeparam name="TContext"></typeparam> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder UseDefaultEFNotificationProcessor <TContext>(this IHarpoonBuilder harpoon) where TContext : DbContext, IRegistrationsContext { harpoon.Services.TryAddScoped <IQueuedProcessor <IWebHookNotification>, EFNotificationProcessor <TContext> >(); return(harpoon); }
/// <summary> /// Registers necessary services for the controllers /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder AddControllers <TWebHookTriggerProvider>(this IHarpoonBuilder harpoon) where TWebHookTriggerProvider : class, IWebHookTriggerProvider { harpoon.Services.TryAddSingleton <IWebHookTriggerProvider, TWebHookTriggerProvider>(); return(harpoon); }
/// <summary> /// Registers <see cref="EFNotificationProcessor{TContext}"/> as the default <see cref="IWebHookService"/>, allowing for a synchronous treatment of <see cref="IWebHookNotification"/> /// </summary> /// <param name="harpoon"></param> /// <returns></returns> public static IHarpoonBuilder ProcessNotificationsSynchronouslyUsingEFDefault <TContext>(this IHarpoonBuilder harpoon) where TContext : DbContext, IRegistrationsContext { harpoon.Services.TryAddScoped <IWebHookService, EFNotificationProcessor <TContext> >(); return(harpoon); }