Skip to content

Commit

Permalink
Reference updates and code documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
tsutomi committed Oct 13, 2023
1 parent 79c2638 commit dc3fb88
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

<ItemGroup>
<PackageReference Include="Finbuckle.MultiTenant.EntityFrameworkCore" Version="6.12.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="7.0.11" />
</ItemGroup>

<ItemGroup>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ internal EntityWebhookStorageBuilder(WebhookSubscriptionBuilder<TSubscription> b
AddDefaultStorage();
}

/// <summary>
/// Gets the entity type to be used to store the results of
/// webhook deliveries in the database.
/// </summary>
public Type? ResultType { get; private set; }

/// <summary>
Expand Down Expand Up @@ -90,6 +94,39 @@ public EntityWebhookStorageBuilder<TSubscription> UseContext<TContext>(Action<Db
return this;
}

/// <summary>
/// Registers the given type of DB context to be used for
/// backing the storage of webhook subscriptions.
/// </summary>
/// <typeparam name="TContext">
/// The type of the <see cref="WebhookDbContext"/> to use.
/// </typeparam>
/// <param name="options">
/// A configuration action that receives an instance of <see cref="ITenantInfo"/>
/// that can be used to configure the options of the context.
/// </param>
/// <param name="lifetime">
/// An optional value that specifies the lifetime of the context.
/// </param>
/// <returns>
/// Returns the current instance of the builder for chaining.
/// </returns>
public EntityWebhookStorageBuilder<TSubscription> UseContext<TContext>(Action<ITenantInfo?, DbContextOptionsBuilder> options, ServiceLifetime lifetime = ServiceLifetime.Scoped)
where TContext : WebhookDbContext {
var factory = (IServiceProvider sp, DbContextOptionsBuilder builder) => {
var tenantInfo = sp.GetService<IMultiTenantContext>()?.TenantInfo;
options(tenantInfo, builder);
};

if (typeof(TContext) != typeof(WebhookDbContext)) {
Services.AddDbContext<WebhookDbContext, TContext>(factory, lifetime);
} else {
Services.AddDbContext<WebhookDbContext>(factory, lifetime);
}

return this;
}

/// <summary>
/// Registers the default type of DB context to be used for
/// backing the storage of webhook subscriptions.
Expand Down Expand Up @@ -125,6 +162,23 @@ public EntityWebhookStorageBuilder<TSubscription> UseSubscriptionStore<TStore>()
return this;
}

/// <summary>
/// Configures the storage to use the given type of result.
/// </summary>
/// <param name="type">
/// The type of the result to use, that must be derived from
/// the <see cref="DbWebhookDeliveryResult"/> type.
/// </param>
/// <returns>
/// Returns the current instance of the builder for chaining.
/// </returns>
/// <exception cref="ArgumentNullException">
/// Thrown when the given <paramref name="type"/> is <c>null</c>.
/// </exception>
/// <exception cref="ArgumentException">
/// Thrown when the given <paramref name="type"/> is not derived from
/// <see cref="DbWebhookDeliveryResult"/>.
/// </exception>
public EntityWebhookStorageBuilder<TSubscription> UseResultType(Type type) {
if (type is null)
throw new ArgumentNullException(nameof(type));
Expand All @@ -137,6 +191,10 @@ public EntityWebhookStorageBuilder<TSubscription> UseResultType(Type type) {
return this;
}

public EntityWebhookStorageBuilder<TSubscription> UseResult<TResult>()
where TResult : DbWebhookDeliveryResult
=> UseResultType(typeof(TResult));

public EntityWebhookStorageBuilder<TSubscription> UseResultStore(Type storeType) {
if (ResultType == null)
throw new InvalidOperationException("No result type was specified for the storage");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Finbuckle.MultiTenant" Version="6.10.0"/>
<PackageReference Include="MongoFramework" Version="0.28.1"/>
<PackageReference Include="Finbuckle.MultiTenant" Version="6.12.0" />
<PackageReference Include="MongoFramework" Version="0.29.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>

<ItemGroup>
Expand Down

0 comments on commit dc3fb88

Please sign in to comment.