Client useful method in instance repository added
This commit is contained in:
@@ -91,7 +91,7 @@ namespace mROA.Implementation.Backend
|
||||
{
|
||||
var context = command.ObjectId.ContextId != -1
|
||||
? instanceRepository.GetObject<object>(command.ObjectId, endPointContext)
|
||||
: instanceRepository.GetSingleObject(invoker.SuitableType, endPointContext);
|
||||
: instanceRepository.GetSingletonObject(invoker.SuitableType, endPointContext);
|
||||
return context;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,13 @@ namespace mROA.Implementation.Backend
|
||||
return (T)value;
|
||||
}
|
||||
|
||||
public object GetSingleObject(Type type, IEndPointContext context)
|
||||
public T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared
|
||||
{
|
||||
return GetSingletonObject(typeof(T), context) as T ??
|
||||
throw new ArgumentException("Unregistered singleton type");
|
||||
}
|
||||
|
||||
public object GetSingletonObject(Type type, IEndPointContext context)
|
||||
{
|
||||
return _singletons.GetValueOrDefault(type.GetHashCode()) ??
|
||||
throw new ArgumentException("Unregistered singleton type");
|
||||
|
||||
@@ -38,10 +38,16 @@ namespace mROA.Implementation.Backend
|
||||
return repository.GetObject<T>(id, context);
|
||||
}
|
||||
|
||||
public object GetSingleObject(Type type, IEndPointContext context)
|
||||
public T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared
|
||||
{
|
||||
var repository = GetRepositoryByClientId(context.OwnerId);
|
||||
return repository.GetSingleObject(type, context);
|
||||
return repository.GetSingletonObject<T>(context);
|
||||
}
|
||||
|
||||
public object GetSingletonObject(Type type, IEndPointContext context)
|
||||
{
|
||||
var repository = GetRepositoryByClientId(context.OwnerId);
|
||||
return repository.GetSingletonObject(type, context);
|
||||
}
|
||||
|
||||
public int GetObjectIndex<T>(object o, IEndPointContext context)
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation
|
||||
{
|
||||
public class ComplexInstanceRepository : IInstanceRepository
|
||||
{
|
||||
private List<KeyValuePair<int, ExtensibleStorage<object>>> _storages = new();
|
||||
public static object[] EventBinders = { };
|
||||
|
||||
private IRemoteObjectFactory? _remoteObjectFactory;
|
||||
private IRepresentationModuleProducer? _representationModuleProducer;
|
||||
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
if (dependency is IRemoteObjectFactory remoteObjectFactory)
|
||||
{
|
||||
_remoteObjectFactory = remoteObjectFactory;
|
||||
}
|
||||
|
||||
if (dependency is IRepresentationModuleProducer moduleProducer)
|
||||
{
|
||||
_representationModuleProducer = moduleProducer;
|
||||
}
|
||||
}
|
||||
|
||||
public int HostId { get; set; }
|
||||
|
||||
public int ResisterObject<T>(object o, IEndPointContext context)
|
||||
{
|
||||
var storageIndex = _storages.FindIndex(i => i.Key == context.OwnerId);
|
||||
if (storageIndex == -1)
|
||||
{
|
||||
_storages.Add(
|
||||
new KeyValuePair<int, ExtensibleStorage<object>>(context.OwnerId, new ExtensibleStorage<object>()));
|
||||
storageIndex = _storages.Count - 1;
|
||||
}
|
||||
|
||||
var storage = _storages[storageIndex].Value;
|
||||
|
||||
var placedIndex = storage.Place(o);
|
||||
EventBinders.OfType<IEventBinder<T>>().FirstOrDefault()
|
||||
?.BindEvents((T)o, context, _representationModuleProducer!, placedIndex);
|
||||
|
||||
return placedIndex;
|
||||
}
|
||||
|
||||
public void ClearObject(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
{
|
||||
_storages.Find(i => i.Key == id.OwnerId).Value.Free(id.ContextId);
|
||||
}
|
||||
|
||||
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public object GetSingleObject(Type type, IEndPointContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public int GetObjectIndex<T>(object o, IEndPointContext context)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,12 @@ namespace mROA.Implementation
|
||||
return remote;
|
||||
}
|
||||
|
||||
public object GetSingleObject(Type type, IEndPointContext context)
|
||||
public T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared
|
||||
{
|
||||
return GetSingletonObject(typeof(T), context) as T;
|
||||
}
|
||||
|
||||
public object GetSingletonObject(Type type, IEndPointContext context)
|
||||
{
|
||||
if (_representationProducer == null)
|
||||
throw new NullReferenceException("representation producer is not initialized");
|
||||
|
||||
Reference in New Issue
Block a user