diff --git a/zero.Api/zero.Api.csproj b/zero.Api/zero.Api.csproj
index 223cc092..32be1e04 100644
--- a/zero.Api/zero.Api.csproj
+++ b/zero.Api/zero.Api.csproj
@@ -32,8 +32,4 @@
-
-
-
-
\ No newline at end of file
diff --git a/zero.Core/Configuration/Integrations/IntegrationStore.cs b/zero.Core/Configuration/Integrations/IntegrationStore.cs
index e4ed5ea2..783fd654 100644
--- a/zero.Core/Configuration/Integrations/IntegrationStore.cs
+++ b/zero.Core/Configuration/Integrations/IntegrationStore.cs
@@ -9,10 +9,10 @@ public class IntegrationStore : IIntegrationStore
protected IIntegrationTypeService IntegrationTypes { get; private set; }
- public IntegrationStore(IStoreContext context, IIntegrationTypeService integrationTypes)
+ public IntegrationStore(IStoreOperationsWithInactive operations, IIntegrationTypeService integrationTypes)
{
IntegrationTypes = integrationTypes;
- Operations = new StoreOperations(context.Context, context.Interceptors, context.Options, new StoreConfig() { IncludeInactive = true });
+ Operations = operations;
}
diff --git a/zero.Core/Identity/Services/UserService.cs b/zero.Core/Identity/Services/UserService.cs
index 07649c35..efc7f163 100644
--- a/zero.Core/Identity/Services/UserService.cs
+++ b/zero.Core/Identity/Services/UserService.cs
@@ -12,14 +12,10 @@ public class UserService : IUserService
protected IZeroContext Context { get; private set; }
- public UserService(IStoreContext store, IZeroContext context, UserManager userManager)
+ public UserService(ISharedStoreOperationsWithInactive operations, IZeroContext context, IZeroOptions options, UserManager userManager)
{
UserManager = userManager;
- Operations = new StoreOperations(store.Context, store.Interceptors, store.Options, new()
- {
- IncludeInactive = true,
- Database = store.Options.For().Database
- });
+ Operations = operations;
Context = context;
}
diff --git a/zero.Core/RecycleBin/RecycledEntity.cs b/zero.Core/RecycleBin/RecycledEntity.cs
index a51befcc..714a2bfd 100644
--- a/zero.Core/RecycleBin/RecycledEntity.cs
+++ b/zero.Core/RecycleBin/RecycledEntity.cs
@@ -2,7 +2,7 @@
//namespace zero.Core.Entities
//{
-// [Collection("RecycleBin")]
+// [RavenCollection("RecycleBin")]
// public class RecycledEntity : ZeroEntity
// {
// ///
diff --git a/zero.Core/Stores/EntityStore.cs b/zero.Core/Stores/EntityStore.cs
index 408f9487..4d6ca9f0 100644
--- a/zero.Core/Stores/EntityStore.cs
+++ b/zero.Core/Stores/EntityStore.cs
@@ -10,11 +10,11 @@ public abstract class EntityStore : IEntityStore where T : ZeroIdEntity, I
public Guid Guid { get; private set; } = Guid.NewGuid();
///
- public IZeroDocumentSession Session => Context.Store.Session(Config.Database);
+ public IZeroDocumentSession Session => Operations.Session;
protected IZeroContext Context { get; private set; }
- protected StoreConfig Config { get; private set; } = new();
+ protected StoreConfig Config => Operations.Config;
protected IInterceptors Interceptors { get; private set; }
@@ -28,7 +28,7 @@ public abstract class EntityStore : IEntityStore where T : ZeroIdEntity, I
Context = collectionContext.Context;
Interceptors = collectionContext.Interceptors;
Options = collectionContext.Options;
- Operations = new StoreOperations(Context, Interceptors, Options, Config);
+ Operations = new StoreOperations(collectionContext);
}
diff --git a/zero.Core/Stores/StoreOperations.cs b/zero.Core/Stores/StoreOperations.cs
index 4394dbb6..2616edeb 100644
--- a/zero.Core/Stores/StoreOperations.cs
+++ b/zero.Core/Stores/StoreOperations.cs
@@ -5,11 +5,18 @@ using System.Security.Claims;
namespace zero.Stores;
-public partial class StoreOperations : IStoreOperations
+public partial class StoreOperations :
+ IStoreOperations,
+ ISharedStoreOperations,
+ IStoreOperationsWithInactive,
+ ISharedStoreOperationsWithInactive
{
///
public IZeroDocumentSession Session => Context.Store.Session(_overrideDatabase ?? Config.Database);
+ ///
+ public StoreConfig Config { get; set; }
+
protected record OperationOptions(bool IncludeInactive);
protected IZeroContext Context { get; private set; }
@@ -18,17 +25,15 @@ public partial class StoreOperations : IStoreOperations
protected FlavorOptions Flavors { get; private set; }
- protected StoreConfig Config { get; private set; }
-
string _overrideDatabase = null;
- public StoreOperations(IZeroContext context, IInterceptors interceptors, IZeroOptions options, StoreConfig config)
+ public StoreOperations(IStoreContext context, StoreConfig config = null)
{
- Context = context;
- Interceptors = interceptors;
- Flavors = options.For();
- Config = config;
+ Context = context.Context;
+ Interceptors = context.Interceptors;
+ Flavors = context.Options.For();
+ Config = config ?? new();
}
@@ -113,6 +118,16 @@ public partial class StoreOperations : IStoreOperations
public interface IStoreOperations
{
+ ///
+ /// Access to the current session
+ ///
+ IZeroDocumentSession Session { get; }
+
+ ///
+ /// Configure operations
+ ///
+ StoreConfig Config { get; set; }
+
///
/// Get new instance of an entity (with an optional flavor)
///
@@ -236,4 +251,9 @@ public interface IStoreOperations
/// Deletes an entity with all descendents
///
Task> DeleteWithDescendants(T model) where T : ZeroIdEntity, ISupportsTrees, new();
-}
\ No newline at end of file
+}
+
+
+public interface ISharedStoreOperations : IStoreOperations { }
+public interface IStoreOperationsWithInactive : IStoreOperations { }
+public interface ISharedStoreOperationsWithInactive : IStoreOperations { }
\ No newline at end of file
diff --git a/zero.Core/Stores/StoresModule.cs b/zero.Core/Stores/StoresModule.cs
index 0f227e46..3ca0edaa 100644
--- a/zero.Core/Stores/StoresModule.cs
+++ b/zero.Core/Stores/StoresModule.cs
@@ -1,5 +1,4 @@
-using Microsoft.AspNetCore.Http.Json;
-using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace zero.Stores;
@@ -11,6 +10,11 @@ public class StoresModule : ZeroModule
services.AddScoped();
services.AddSingleton();
+ services.AddTransient();
+ services.AddTransient(x => new StoreOperations(x.GetRequiredService(), new() { Database = x.GetRequiredService().For().Database }));
+ services.AddTransient(x => new StoreOperations(x.GetRequiredService(), new() { IncludeInactive = true }));
+ services.AddTransient(x => new StoreOperations(x.GetRequiredService(), new() { Database = x.GetRequiredService().For().Database, IncludeInactive = true }));
+
services.AddOptions();
services.ConfigureOptions();