Добавлена простая абстракция для создания удаленных объектов
This commit is contained in:
@@ -0,0 +1,9 @@
|
|||||||
|
using mROA.Implementation;
|
||||||
|
|
||||||
|
namespace mROA.Abstract
|
||||||
|
{
|
||||||
|
public interface IRemoteObjectFactory : IInjectableModule
|
||||||
|
{
|
||||||
|
T Produce<T>(ComplexObjectIdentifier id);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,9 +12,10 @@ namespace mROA.Implementation
|
|||||||
{
|
{
|
||||||
ContextId = contextId;
|
ContextId = contextId;
|
||||||
OwnerId = ownerId;
|
OwnerId = ownerId;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ComplexObjectIdentifier Singleton(int ownerId) => new() { ContextId = -1, OwnerId = ownerId };
|
||||||
|
|
||||||
public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 };
|
public static ComplexObjectIdentifier Null = new ComplexObjectIdentifier { ContextId = -2, OwnerId = -1 };
|
||||||
public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
|
public static ComplexObjectIdentifier FromFlat(ulong flat) => new() { Flat = flat };
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
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)
|
||||||
|
{
|
||||||
|
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(TransmissionConfig.OwnershipRepository.GetOwnershipId());
|
||||||
|
var remote = (T)Activator.CreateInstance(remoteType, id.ContextId,
|
||||||
|
representationModule)!;
|
||||||
|
return remote;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Inject<T>(T dependency)
|
||||||
|
{
|
||||||
|
if (dependency is IRepresentationModuleProducer serialisationModule)
|
||||||
|
_representationProducer = serialisationModule;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user