Rewrite to direct constructors

This commit is contained in:
2025-06-27 17:51:52 +03:00
parent 80490947b1
commit acb5a2cf58
13 changed files with 38 additions and 55 deletions
@@ -49,7 +49,7 @@ namespace mROA.Implementation.Backend
_storage.Free(id.ContextId);
}
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
{
var value = _storage.GetValue(id.ContextId);
@@ -32,7 +32,7 @@ namespace mROA.Implementation.Backend
repository.ClearObject(id, context);
}
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
{
var repository = GetRepositoryByClientId(context.OwnerId);
return repository.GetObject<T>(id, context);
@@ -6,10 +6,11 @@ namespace mROA.Implementation.Bootstrap
{
public class FullMixBuilder
{
public List<IInjectableModule> Modules { get; } = new() { };
public List<IInjectableModule> Modules { get; } = new();
public void Build()
{
foreach (var module in Modules)
foreach (var injection in Modules)
module.Inject(injection);
+1
View File
@@ -23,6 +23,7 @@ namespace mROA.Implementation
public override string ToString()
{
return $"Call request {{ Id : {Id}, CommandId : {CommandId}, ObjectId : {ObjectId} }}";
}
}
+15 -12
View File
@@ -8,7 +8,10 @@ namespace mROA.Implementation
public class RemoteInstanceRepository : IInstanceRepository
{
private List<RemoteObjectBase> _producedProxys = new();
public static Dictionary<Type, Type> RemoteTypes = new();
public static Dictionary<Type, Func<int, IRepresentationModule, IEndPointContext, RemoteObjectBase>>
RemoteTypeFactories = new();
private IRepresentationModuleProducer? _representationProducer;
public int HostId { get; set; }
@@ -23,7 +26,7 @@ namespace mROA.Implementation
throw new NotSupportedException();
}
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context)
public T GetObject<T>(ComplexObjectIdentifier id, IEndPointContext context) where T : class
{
var index = _producedProxys.Find(i => i.Identifier.Equals(id));
if (index is not null)
@@ -31,20 +34,20 @@ namespace mROA.Implementation
if (_representationProducer == null)
throw new NullReferenceException("representation producer is not initialized");
if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
if (!RemoteTypeFactories.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
var representationModule =
_representationProducer.Produce(context.OwnerId);
var remote = (T)Activator.CreateInstance(remoteType, id.ContextId,
representationModule, context)!;
var remote = remoteType(id.ContextId,
representationModule, context);
_producedProxys.Add((remote as RemoteObjectBase)!);
_producedProxys.Add(remote!);
return remote;
return (remote as T)!;
}
public T GetSingletonObject<T>(IEndPointContext context) where T : class, IShared
{
return GetSingletonObject(typeof(T), context) as T;
return (GetSingletonObject(typeof(T), context) as T)!;
}
public object GetSingletonObject(Type type, IEndPointContext context)
@@ -55,10 +58,10 @@ namespace mROA.Implementation
var representationModule =
_representationProducer.Produce(context.OwnerId);
var instance = Activator.CreateInstance(RemoteTypes[type], -1, representationModule, context);
var remoteObjectBase = (RemoteObjectBase)instance;
var instance = RemoteTypeFactories[type](-1, representationModule, context)!;
var remoteObjectBase = instance;
_producedProxys.Add(remoteObjectBase);
return _producedProxys.Last();
@@ -1,31 +0,0 @@
using System;
using System.Collections.Generic;
using mROA.Abstract;
namespace mROA.Implementation
{
public class RemoteObjectFactory : IRemoteObjectFactory
{
public static Dictionary<Type, Type> RemoteTypes = new();
private IRepresentationModuleProducer? _representationProducer;
public T Produce<T>(ComplexObjectIdentifier id, IEndPointContext context)
{
if (_representationProducer == null)
throw new NullReferenceException("representation producer is not initialized");
if (!RemoteTypes.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException();
var representationModule =
_representationProducer.Produce(context.OwnerId);
var remote = (T)Activator.CreateInstance(remoteType, id.ContextId,
representationModule)!;
return remote;
}
public void Inject<T>(T dependency)
{
if (dependency is IRepresentationModuleProducer serialisationModule)
_representationProducer = serialisationModule;
}
}
}
+2 -2
View File
@@ -16,7 +16,7 @@ namespace mROA.Implementation
object UniversalValue { get; set; }
}
public class SharedObjectShellShell<T> : ISharedObjectShell where T : notnull
public class SharedObjectShellShell<T> : ISharedObjectShell where T : class
{
private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null;
@@ -26,7 +26,7 @@ namespace mROA.Implementation
// ReSharper disable once UnusedMember.Global
public SharedObjectShellShell()
{
_value = default;
_value = null;
EndPointContext = new EndPointContext();
}