diff --git a/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.csproj b/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.csproj index 762257b..06dc283 100644 --- a/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.csproj +++ b/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.xml b/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.xml index c184387..7263775 100644 --- a/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.xml +++ b/src/Deveel.Webhooks.Service.EntityFramework/Deveel.Webhooks.EntityFramework.xml @@ -332,6 +332,12 @@ The type of the entity to use + + + Gets the entity type to be used to store the results of + webhook deliveries in the database. + + Gets the that is used to @@ -357,6 +363,25 @@ Returns the current instance of the builder for chaining. + + + Registers the given type of DB context to be used for + backing the storage of webhook subscriptions. + + + The type of the to use. + + + A configuration action that receives an instance of + that can be used to configure the options of the context. + + + An optional value that specifies the lifetime of the context. + + + Returns the current instance of the builder for chaining. + + Registers the default type of DB context to be used for @@ -385,6 +410,25 @@ Returns the current instance of the builder for chaining. + + + Configures the storage to use the given type of result. + + + The type of the result to use, that must be derived from + the type. + + + Returns the current instance of the builder for chaining. + + + Thrown when the given is null. + + + Thrown when the given is not derived from + . + + A default implementation of that diff --git a/src/Deveel.Webhooks.Service.EntityFramework/Webhooks/EntityWebhookStorageBuilder.cs b/src/Deveel.Webhooks.Service.EntityFramework/Webhooks/EntityWebhookStorageBuilder.cs index ce5738a..39fbf9e 100644 --- a/src/Deveel.Webhooks.Service.EntityFramework/Webhooks/EntityWebhookStorageBuilder.cs +++ b/src/Deveel.Webhooks.Service.EntityFramework/Webhooks/EntityWebhookStorageBuilder.cs @@ -35,6 +35,10 @@ internal EntityWebhookStorageBuilder(WebhookSubscriptionBuilder b AddDefaultStorage(); } + /// + /// Gets the entity type to be used to store the results of + /// webhook deliveries in the database. + /// public Type? ResultType { get; private set; } /// @@ -90,6 +94,39 @@ public EntityWebhookStorageBuilder UseContext(Action + /// Registers the given type of DB context to be used for + /// backing the storage of webhook subscriptions. + /// + /// + /// The type of the to use. + /// + /// + /// A configuration action that receives an instance of + /// that can be used to configure the options of the context. + /// + /// + /// An optional value that specifies the lifetime of the context. + /// + /// + /// Returns the current instance of the builder for chaining. + /// + public EntityWebhookStorageBuilder UseContext(Action options, ServiceLifetime lifetime = ServiceLifetime.Scoped) + where TContext : WebhookDbContext { + var factory = (IServiceProvider sp, DbContextOptionsBuilder builder) => { + var tenantInfo = sp.GetService()?.TenantInfo; + options(tenantInfo, builder); + }; + + if (typeof(TContext) != typeof(WebhookDbContext)) { + Services.AddDbContext(factory, lifetime); + } else { + Services.AddDbContext(factory, lifetime); + } + + return this; + } + /// /// Registers the default type of DB context to be used for /// backing the storage of webhook subscriptions. @@ -125,6 +162,23 @@ public EntityWebhookStorageBuilder UseSubscriptionStore() return this; } + /// + /// Configures the storage to use the given type of result. + /// + /// + /// The type of the result to use, that must be derived from + /// the type. + /// + /// + /// Returns the current instance of the builder for chaining. + /// + /// + /// Thrown when the given is null. + /// + /// + /// Thrown when the given is not derived from + /// . + /// public EntityWebhookStorageBuilder UseResultType(Type type) { if (type is null) throw new ArgumentNullException(nameof(type)); @@ -137,6 +191,10 @@ public EntityWebhookStorageBuilder UseResultType(Type type) { return this; } + public EntityWebhookStorageBuilder UseResult() + where TResult : DbWebhookDeliveryResult + => UseResultType(typeof(TResult)); + public EntityWebhookStorageBuilder UseResultStore(Type storeType) { if (ResultType == null) throw new InvalidOperationException("No result type was specified for the storage"); diff --git a/src/Deveel.Webhooks.Service.MongoDb/Deveel.Webhooks.MongoDb.csproj b/src/Deveel.Webhooks.Service.MongoDb/Deveel.Webhooks.MongoDb.csproj index eaca405..51561c7 100644 --- a/src/Deveel.Webhooks.Service.MongoDb/Deveel.Webhooks.MongoDb.csproj +++ b/src/Deveel.Webhooks.Service.MongoDb/Deveel.Webhooks.MongoDb.csproj @@ -14,8 +14,8 @@ - - + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 121d272..4aa17a5 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -27,7 +27,7 @@ - +