Добавлена простая абстракция для создания удаленных объектов

This commit is contained in:
2025-03-11 15:02:36 +03:00
parent 8beca7f8d7
commit 76f395dce5
3 changed files with 42 additions and 1 deletions
@@ -12,9 +12,10 @@ namespace mROA.Implementation
{
ContextId = contextId;
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 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;
}
}
}