2
0
mirror of https://github.com/esiur/esiur-dotnet.git synced 2025-09-13 12:43:17 +00:00
This commit is contained in:
2025-08-24 02:11:50 +03:00
parent 0d4ea04ef4
commit b12939e109
8 changed files with 149 additions and 79 deletions

View File

@@ -127,7 +127,7 @@ public class EntityStore : IStore
public IResource GetById(Type type, object id)
{
if (!initialized)
throw new Exception("Store not initalized. Make sure the Warehouse is open.");
throw new Exception("Store is not initialized. Make sure the Warehouse is open.");
lock (DBLock)
{

View File

@@ -35,6 +35,7 @@ using Microsoft.EntityFrameworkCore.Metadata;
using System.Reflection;
using Esiur.Proxy;
using Microsoft.EntityFrameworkCore;
using Esiur.Resource;
namespace Esiur.Stores.EntityCore;
@@ -50,13 +51,15 @@ public class EsiurExtensionOptions : IDbContextOptionsExtension
private DbContextOptionsExtensionInfo _info;
DbContextOptionsExtensionInfo _info;
EntityStore _store;
Warehouse _warehouse;
public DbContextOptionsExtensionInfo Info => _info;
public EntityStore Store => _store;
public Warehouse Warehouse => _warehouse;
public void ApplyServices(IServiceCollection services)
{
@@ -84,6 +87,7 @@ public class EsiurExtensionOptions : IDbContextOptionsExtension
{
_info = new ExtensionInfo(this);
_store = store;
_warehouse = store.Instance.Warehouse;
}

View File

@@ -57,7 +57,8 @@ public static class EsiurExtensions
public static async AsyncReply<T> AddResourceAsync<T>(this DbSet<T> dbSet, T resource) where T : class, IResource
{
var store = dbSet.GetInfrastructure().GetService<IDbContextOptions>().FindExtension<EsiurExtensionOptions>().Store;
var options = dbSet.GetInfrastructure().GetService<IDbContextOptions>().FindExtension<EsiurExtensionOptions>();
var store = options.Store;
if (store == null)
throw new Exception("Store not set, please call 'UseEsiur' on your DbContextOptionsBuilder.");
@@ -89,7 +90,6 @@ public static class EsiurExtensions
foreach (var p in ps)
{
var mi = resType.GetMember(p.Key, System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance)
.FirstOrDefault();
@@ -131,7 +131,7 @@ public static class EsiurExtensions
var id = store.TypesByType[typeof(T)].PrimaryKey.GetValue(resource);
await Warehouse.Put(id.ToString(), res, store, null, null, 0, manager);
await options.Warehouse.Put(id.ToString(), res, store, null, 0, manager);
return (T)res;
}

View File

@@ -69,11 +69,10 @@ public class EsiurProxyRewrite : IModelFinalizingConvention
if (Codec.ImplementsInterface(entityType.ClrType, typeof(IResource)))
{
// check if the object exists
var obj = Warehouse.New(entityType.ClrType).Wait() as IResource;
var obj = options.Warehouse.CreateInstance(entityType.ClrType) as IResource;
options.Store.TypesByType[entityType.ClrType].PrimaryKey.SetValue(obj, id);
Warehouse.Put(id.ToString(), obj, options.Store, null, null, 0, manager).Wait();
options.Warehouse.Put(id.ToString(), obj, options.Store, null, 0, manager).Wait();
return obj;
}
else
{