Replace BLite with Surreal embedded persistence
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m21s
All checks were successful
NuGet Package Publish / nuget (push) Successful in 1m21s
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.DependencyInjection.Extensions;
|
||||
using ZB.MOM.WW.CBDDC.Core.Network;
|
||||
using SurrealDb.Net;
|
||||
using ZB.MOM.WW.CBDDC.Core.Storage;
|
||||
using ZB.MOM.WW.CBDDC.Core.Sync;
|
||||
|
||||
namespace ZB.MOM.WW.CBDDC.Persistence.Surreal;
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for configuring embedded Surreal persistence for CBDDC.
|
||||
/// </summary>
|
||||
public static class CBDDCSurrealEmbeddedExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Adds embedded Surreal infrastructure to CBDDC and registers a document store implementation.
|
||||
/// </summary>
|
||||
/// <typeparam name="TDocumentStore">The concrete document store implementation.</typeparam>
|
||||
/// <param name="services">The service collection to add services to.</param>
|
||||
/// <param name="optionsFactory">Factory used to build embedded Surreal options.</param>
|
||||
/// <returns>The service collection for chaining.</returns>
|
||||
public static IServiceCollection AddCBDDCSurrealEmbedded<TDocumentStore>(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, CBDDCSurrealEmbeddedOptions> optionsFactory)
|
||||
where TDocumentStore : class, IDocumentStore
|
||||
{
|
||||
RegisterCoreServices(services, optionsFactory);
|
||||
services.TryAddSingleton<IDocumentStore, TDocumentStore>();
|
||||
return services;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds embedded Surreal infrastructure to CBDDC without registering store implementations.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection to add services to.</param>
|
||||
/// <param name="optionsFactory">Factory used to build embedded Surreal options.</param>
|
||||
/// <returns>The service collection for chaining.</returns>
|
||||
/// <remarks>
|
||||
/// Register store implementations separately when they become available.
|
||||
/// </remarks>
|
||||
public static IServiceCollection AddCBDDCSurrealEmbedded(
|
||||
this IServiceCollection services,
|
||||
Func<IServiceProvider, CBDDCSurrealEmbeddedOptions> optionsFactory)
|
||||
{
|
||||
RegisterCoreServices(services, optionsFactory);
|
||||
return services;
|
||||
}
|
||||
|
||||
private static void RegisterCoreServices(
|
||||
IServiceCollection services,
|
||||
Func<IServiceProvider, CBDDCSurrealEmbeddedOptions> optionsFactory)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
if (optionsFactory == null) throw new ArgumentNullException(nameof(optionsFactory));
|
||||
|
||||
services.TryAddSingleton(optionsFactory);
|
||||
|
||||
services.TryAddSingleton<ICBDDCSurrealEmbeddedClient, CBDDCSurrealEmbeddedClient>();
|
||||
services.TryAddSingleton<ISurrealDbClient>(sp => sp.GetRequiredService<ICBDDCSurrealEmbeddedClient>().Client);
|
||||
services.TryAddSingleton<ICBDDCSurrealSchemaInitializer, CBDDCSurrealSchemaInitializer>();
|
||||
services.TryAddSingleton<ICBDDCSurrealReadinessProbe, CBDDCSurrealReadinessProbe>();
|
||||
services.TryAddSingleton<ISurrealCdcCheckpointPersistence, SurrealCdcCheckpointPersistence>();
|
||||
|
||||
services.TryAddSingleton<IConflictResolver, LastWriteWinsConflictResolver>();
|
||||
services.TryAddSingleton<IVectorClockService, VectorClockService>();
|
||||
services.TryAddSingleton<IPeerConfigurationStore, SurrealPeerConfigurationStore>();
|
||||
services.TryAddSingleton<IPeerOplogConfirmationStore, SurrealPeerOplogConfirmationStore>();
|
||||
services.TryAddSingleton<ISnapshotMetadataStore, SurrealSnapshotMetadataStore>();
|
||||
services.TryAddSingleton<IDocumentMetadataStore, SurrealDocumentMetadataStore>();
|
||||
services.TryAddSingleton<IOplogStore, SurrealOplogStore>();
|
||||
|
||||
// SnapshotStore registration matches the other provider extension patterns.
|
||||
services.TryAddSingleton<ISnapshotService, SnapshotStore>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user