* Implemented MongoDb * Use main entity models in mongodb * Fixed object serialization issue * Fixed issues caused by duplicate collection names * Optimized count query * Fixed the issues after merge * Revert "Fixed the issues after merge" This reverts commit 5568af60cfc107b8ee68fd4c89fbb02946f8a6a3. * Use expression helper to solve mongodb query issue * Handle null values during deserialization * Moved MongoDb project to persistence folder * Did some refactor and added type serializer for variable fix * Modularize mongodb indices creation * Fixed the build * Implement variable serializer * Update SQLite migrations --------- Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
42 lines
1.4 KiB
C#
42 lines
1.4 KiB
C#
using Elsa.Features.Abstractions;
|
|
using Elsa.Features.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using MongoDB.Driver;
|
|
|
|
namespace Elsa.MongoDb.Common;
|
|
|
|
/// <summary>
|
|
/// Base class for features that configure MongoDb persistence.
|
|
/// </summary>
|
|
public abstract class PersistenceFeatureBase : FeatureBase
|
|
{
|
|
/// <inheritdoc />
|
|
protected PersistenceFeatureBase(IModule module) : base(module)
|
|
{
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registers a <see cref="MongoDbStore{TDocument}"/>.
|
|
/// </summary>
|
|
/// <typeparam name="TStore">The type of the store.</typeparam>
|
|
/// <typeparam name="TDocument">The document type of the store.</typeparam>
|
|
protected void AddStore<TDocument, TStore>() where TDocument : class where TStore : class
|
|
{
|
|
Services
|
|
.AddSingleton<MongoDbStore<TDocument>>()
|
|
.AddSingleton<TStore>()
|
|
;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Registers a <see cref="IMongoCollection{TDocument}"/>.
|
|
/// </summary>
|
|
/// <param name="collectionName">The name of the collection.</param>
|
|
/// <typeparam name="TDocument">The document type of the collection.</typeparam>
|
|
protected void AddCollection<TDocument>(string collectionName) where TDocument : class
|
|
{
|
|
Services.AddSingleton(
|
|
sp => sp.GetRequiredService<IMongoDatabase>()
|
|
.GetCollection<TDocument>(collectionName));
|
|
}
|
|
} |