Files
mixtape/zero.Core/Persistence/ZeroDocumentSession.cs
T

52 lines
1.3 KiB
C#
Raw Normal View History

2021-11-19 14:59:24 +01:00
using Raven.Client.Documents;
using Raven.Client.Documents.Session;
2021-11-20 13:52:28 +01:00
namespace zero.Persistence;
2021-11-19 14:59:24 +01:00
public class ZeroDocumentSession : AsyncDocumentSession, IZeroDocumentSession
{
public IZeroDocumentSession Core { get; private set; }
2021-12-03 14:45:49 +01:00
public IDocumentSession Synchronous => _synchronous ?? (_synchronous = DocumentStore.OpenSession(DatabaseName));
IDocumentSession _synchronous;
2021-11-19 14:59:24 +01:00
public ZeroDocumentSession(DocumentStore documentStore, Guid id, SessionOptions options, string coreDatabase = null) : base(documentStore, id, options)
{
if (coreDatabase.HasValue())
{
Core = new ZeroDocumentSession(documentStore, id, new SessionOptions()
{
Database = coreDatabase,
DisableAtomicDocumentWritesInClusterWideTransaction = options.DisableAtomicDocumentWritesInClusterWideTransaction,
NoCaching = options.NoCaching,
NoTracking = options.NoTracking,
RequestExecutor = options.RequestExecutor,
TransactionMode = options.TransactionMode
});
}
else
{
Core = this;
}
}
public bool IsDisposed { get; set; }
2021-12-03 14:45:49 +01:00
public override void Dispose()
{
_synchronous?.Dispose();
base.Dispose();
}
2021-11-19 14:59:24 +01:00
}
public interface IZeroDocumentSession : IAsyncDocumentSession
{
IZeroDocumentSession Core { get; }
2021-12-03 14:45:49 +01:00
IDocumentSession Synchronous { get; }
2021-11-19 14:59:24 +01:00
bool IsDisposed { get; }
}