Renaming context repository to instance repository

This commit is contained in:
2025-05-07 23:50:15 +03:00
parent 730302aed8
commit dbde8c3d30
16 changed files with 46 additions and 79 deletions
+3 -3
View File
@@ -30,11 +30,11 @@ class Program
builder.Modules.Add(new CreativeRepresentationModuleProducer( builder.Modules.Add(new CreativeRepresentationModuleProducer(
new IInjectableModule[] { builder.GetModule<IContextualSerializationToolKit>()! }, new IInjectableModule[] { builder.GetModule<IContextualSerializationToolKit>()! },
typeof(RepresentationModule))); typeof(RepresentationModule)));
builder.Modules.Add(new RemoteContextRepository()); builder.Modules.Add(new RemoteInstanceRepository());
// builder.UseCollectableContextRepository(typeof(PrinterFactory).Assembly); // builder.UseCollectableContextRepository(typeof(PrinterFactory).Assembly);
builder.Modules.Add(new MultiClientContextRepository(i => builder.Modules.Add(new MultiClientInstanceRepository(i =>
{ {
var repo = new ContextRepository(); var repo = new InstanceRepository();
repo.FillSingletons(typeof(PrinterFactory).Assembly); repo.FillSingletons(typeof(PrinterFactory).Assembly);
repo.Inject(builder.Modules.OfType<CreativeRepresentationModuleProducer>().First()); repo.Inject(builder.Modules.OfType<CreativeRepresentationModuleProducer>().First());
return repo; return repo;
+2 -2
View File
@@ -23,7 +23,7 @@ class Program
builder.Modules.Add(new CborSerializationToolkit()); builder.Modules.Add(new CborSerializationToolkit());
builder.Modules.Add(new EndPointContext()); builder.Modules.Add(new EndPointContext());
builder.Modules.Add(new RemoteContextRepository()); builder.Modules.Add(new RemoteInstanceRepository());
builder.Modules.Add(new ChannelInteractionModule()); builder.Modules.Add(new ChannelInteractionModule());
builder.Modules.Add(new UdpUntrustedInteraction()); builder.Modules.Add(new UdpUntrustedInteraction());
builder.Modules.Add(new RepresentationModule()); builder.Modules.Add(new RepresentationModule());
@@ -43,7 +43,7 @@ class Program
_ = builder.GetModule<RequestExtractor>()!.StartExtraction(); _ = builder.GetModule<RequestExtractor>()!.StartExtraction();
_ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint); _ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint);
Console.WriteLine(builder.GetModule<IEndPointContext>().HostId); Console.WriteLine(builder.GetModule<IEndPointContext>().HostId);
var context = builder.GetModule<RemoteContextRepository>(); var context = builder.GetModule<RemoteInstanceRepository>();
var factory = var factory =
context.GetSingleObject(typeof(IPrinterFactory), context.GetSingleObject(typeof(IPrinterFactory),
+1 -1
View File
@@ -2,7 +2,7 @@ namespace mROA.Abstract
{ {
public interface IContextRepositoryHub public interface IContextRepositoryHub
{ {
IContextRepository GetRepository(int clientId); IInstanceRepository GetRepository(int clientId);
void FreeRepository(int clientId); void FreeRepository(int clientId);
} }
} }
+2 -2
View File
@@ -2,8 +2,8 @@
{ {
public interface IEndPointContext : IInjectableModule public interface IEndPointContext : IInjectableModule
{ {
IContextRepository RealRepository { get; } IInstanceRepository RealRepository { get; }
IContextRepository RemoteRepository { get; } IInstanceRepository RemoteRepository { get; }
int HostId { get; set; } int HostId { get; set; }
int OwnerId { get; set; } int OwnerId { get; set; }
} }
+1 -1
View File
@@ -4,7 +4,7 @@ namespace mROA.Abstract
{ {
public interface IExecuteModule : IInjectableModule public interface IExecuteModule : IInjectableModule
{ {
ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository, ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
IRepresentationModule representationModule, IEndPointContext context); IRepresentationModule representationModule, IEndPointContext context);
} }
} }
@@ -3,7 +3,7 @@ using mROA.Implementation;
namespace mROA.Abstract namespace mROA.Abstract
{ {
public interface IContextRepository : IInjectableModule public interface IInstanceRepository : IInjectableModule
{ {
int HostId { get; set; } int HostId { get; set; }
int ResisterObject<T>(object o, IEndPointContext context); int ResisterObject<T>(object o, IEndPointContext context);
@@ -21,7 +21,7 @@ namespace mROA.Implementation.Backend
public static void UseCollectableContextRepository(this FullMixBuilder builder, params Assembly[] assemblies) public static void UseCollectableContextRepository(this FullMixBuilder builder, params Assembly[] assemblies)
{ {
var repo = new ContextRepository(); var repo = new InstanceRepository();
repo.FillSingletons(assemblies); repo.FillSingletons(assemblies);
builder.Modules.Add(repo); builder.Modules.Add(repo);
} }
@@ -27,13 +27,13 @@ namespace mROA.Implementation.Backend
} }
} }
public ICommandExecution Execute(ICallRequest command, IContextRepository contextRepository, public ICommandExecution Execute(ICallRequest command, IInstanceRepository instanceRepository,
IRepresentationModule representationModule, IEndPointContext endPointContext) IRepresentationModule representationModule, IEndPointContext endPointContext)
{ {
try try
{ {
ThrowIfNotInjected(contextRepository); ThrowIfNotInjected(instanceRepository);
if (command is CancelRequest) if (command is CancelRequest)
{ {
return CancelExecution(command); return CancelExecution(command);
@@ -43,7 +43,7 @@ namespace mROA.Implementation.Backend
if (invoker == null) if (invoker == null)
throw new Exception($"Command {command.CommandId} not found"); throw new Exception($"Command {command.CommandId} not found");
var context = GetContext(command, contextRepository, invoker, endPointContext); var context = GetContext(command, instanceRepository, invoker, endPointContext);
if (context == null) if (context == null)
throw new NullReferenceException("Instance can't be null"); throw new NullReferenceException("Instance can't be null");
@@ -70,7 +70,7 @@ namespace mROA.Implementation.Backend
var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext); var result = Execute((invoker as MethodInvoker)!, context, castedParams!, command, execContext);
if (command.CommandId == -1) if (command.CommandId == -1)
{ {
contextRepository.ClearObject(command.ObjectId, endPointContext); instanceRepository.ClearObject(command.ObjectId, endPointContext);
} }
return result; return result;
@@ -86,12 +86,12 @@ namespace mROA.Implementation.Backend
} }
} }
private static object GetContext(ICallRequest command, IContextRepository contextRepository, private static object GetContext(ICallRequest command, IInstanceRepository instanceRepository,
IMethodInvoker invoker, IEndPointContext endPointContext) IMethodInvoker invoker, IEndPointContext endPointContext)
{ {
var context = command.ObjectId.ContextId != -1 var context = command.ObjectId.ContextId != -1
? contextRepository.GetObject<object>(command.ObjectId, endPointContext) ? instanceRepository.GetObject<object>(command.ObjectId, endPointContext)
: contextRepository.GetSingleObject(invoker.SuitableType, endPointContext); : instanceRepository.GetSingleObject(invoker.SuitableType, endPointContext);
return context; return context;
} }
@@ -106,7 +106,7 @@ namespace mROA.Implementation.Backend
return castedParams; return castedParams;
} }
private void ThrowIfNotInjected(IContextRepository contextRepository) private void ThrowIfNotInjected(IInstanceRepository instanceRepository)
{ {
if (_cancellationRepo is null) if (_cancellationRepo is null)
throw new NullReferenceException("Method repository was not defined"); throw new NullReferenceException("Method repository was not defined");
@@ -114,7 +114,7 @@ namespace mROA.Implementation.Backend
if (_methodRepo is null) if (_methodRepo is null)
throw new NullReferenceException("Method repository was not defined"); throw new NullReferenceException("Method repository was not defined");
if (contextRepository is null) if (instanceRepository is null)
throw new NullReferenceException("Context repository was not defined"); throw new NullReferenceException("Context repository was not defined");
} }
@@ -7,8 +7,8 @@ namespace mROA.Implementation.Backend
{ {
private IConnectionHub? _hub; private IConnectionHub? _hub;
private IContextRepository? _contextRepository; private IInstanceRepository? _contextRepository;
private IContextRepository? _remoteContextRepository; private IInstanceRepository? _remoteContextRepository;
private IMethodRepository? _methodRepository; private IMethodRepository? _methodRepository;
private IContextualSerializationToolKit? _serializationToolkit; private IContextualSerializationToolKit? _serializationToolkit;
private IExecuteModule? _executeModule; private IExecuteModule? _executeModule;
@@ -21,11 +21,11 @@ namespace mROA.Implementation.Backend
_hub = connectionHub; _hub = connectionHub;
_hub.OnConnected += HubOnOnConnected; _hub.OnConnected += HubOnOnConnected;
break; break;
case MultiClientContextRepository: case MultiClientInstanceRepository:
case ContextRepository: case InstanceRepository:
_contextRepository = dependency as IContextRepository; _contextRepository = dependency as IInstanceRepository;
break; break;
case RemoteContextRepository remoteContextRepository: case RemoteInstanceRepository remoteContextRepository:
_remoteContextRepository = remoteContextRepository; _remoteContextRepository = remoteContextRepository;
break; break;
case IMethodRepository methodRepository: case IMethodRepository methodRepository:
@@ -8,7 +8,7 @@ using mROA.Implementation.Attributes;
namespace mROA.Implementation.Backend namespace mROA.Implementation.Backend
{ {
public class ContextRepository : IContextRepository public class InstanceRepository : IInstanceRepository
{ {
public static object[] EventBinders = { }; public static object[] EventBinders = { };
@@ -22,7 +22,7 @@ namespace mROA.Implementation.Backend
private IStorage<object> _storage; private IStorage<object> _storage;
public ContextRepository() public InstanceRepository()
{ {
_storage = new ExtensibleStorage<object>(); _storage = new ExtensibleStorage<object>();
} }
@@ -4,12 +4,12 @@ using mROA.Abstract;
namespace mROA.Implementation.Backend namespace mROA.Implementation.Backend
{ {
public class MultiClientContextRepository : IContextRepository, IContextRepositoryHub public class MultiClientInstanceRepository : IInstanceRepository, IContextRepositoryHub
{ {
private readonly Func<int, IContextRepository> _produceRepository; private readonly Func<int, IInstanceRepository> _produceRepository;
private readonly Dictionary<int, IContextRepository> _repositories = new(); private readonly Dictionary<int, IInstanceRepository> _repositories = new();
public MultiClientContextRepository(Func<int, IContextRepository> produceRepository) public MultiClientInstanceRepository(Func<int, IInstanceRepository> produceRepository)
{ {
_produceRepository = produceRepository; _produceRepository = produceRepository;
} }
@@ -50,7 +50,7 @@ namespace mROA.Implementation.Backend
return repository.GetObjectIndex<T>(o, context); return repository.GetObjectIndex<T>(o, context);
} }
public IContextRepository GetRepository(int clientId) public IInstanceRepository GetRepository(int clientId)
{ {
var repository = GetRepositoryByClientId(clientId); var repository = GetRepositoryByClientId(clientId);
return repository; return repository;
@@ -61,7 +61,7 @@ namespace mROA.Implementation.Backend
_repositories.Remove(clientId); _repositories.Remove(clientId);
} }
private IContextRepository GetRepositoryByClientId(int clientId) private IInstanceRepository GetRepositoryByClientId(int clientId)
{ {
if (_repositories.TryGetValue(clientId, out var repository)) if (_repositories.TryGetValue(clientId, out var repository))
return repository; return repository;
@@ -5,7 +5,7 @@ using mROA.Abstract;
namespace mROA.Implementation namespace mROA.Implementation
{ {
public class ComplexContextRepository : IContextRepository public class ComplexInstanceRepository : IInstanceRepository
{ {
private List<KeyValuePair<int, ExtensibleStorage<object>>> _storages = new(); private List<KeyValuePair<int, ExtensibleStorage<object>>> _storages = new();
public static object[] EventBinders = { }; public static object[] EventBinders = { };
+4 -4
View File
@@ -6,8 +6,8 @@ namespace mROA.Implementation
{ {
public class EndPointContext : IEndPointContext public class EndPointContext : IEndPointContext
{ {
public IContextRepository RealRepository { get; set; } public IInstanceRepository RealRepository { get; set; }
public IContextRepository RemoteRepository { get; set; } public IInstanceRepository RemoteRepository { get; set; }
public int HostId { get; set; } public int HostId { get; set; }
public int OwnerId { get; set; } public int OwnerId { get; set; }
@@ -16,10 +16,10 @@ namespace mROA.Implementation
{ {
switch (dependency) switch (dependency)
{ {
case RemoteContextRepository remoteRepository: case RemoteInstanceRepository remoteRepository:
RemoteRepository = remoteRepository; RemoteRepository = remoteRepository;
break; break;
case ContextRepository realRepository: case InstanceRepository realRepository:
RealRepository = realRepository; RealRepository = realRepository;
break; break;
} }
@@ -5,7 +5,7 @@ using mROA.Abstract;
namespace mROA.Implementation namespace mROA.Implementation
{ {
public class RemoteContextRepository : IContextRepository public class RemoteInstanceRepository : IInstanceRepository
{ {
private List<RemoteObjectBase> _producedRemoteEndpoints = new(); private List<RemoteObjectBase> _producedRemoteEndpoints = new();
public static Dictionary<Type, Type> RemoteTypes = new(); public static Dictionary<Type, Type> RemoteTypes = new();
+6 -4
View File
@@ -20,12 +20,14 @@ namespace mROA.Implementation
{ {
private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null; private ComplexObjectIdentifier _identifier = ComplexObjectIdentifier.Null;
private T _value; private T? _value;
// ReSharper disable once MemberCanBePrivate.Global // ReSharper disable once MemberCanBePrivate.Global
// ReSharper disable once UnusedMember.Global // ReSharper disable once UnusedMember.Global
public SharedObjectShellShell() public SharedObjectShellShell()
{ {
_value = default;
EndPointContext = new EndPointContext();
} }
// ReSharper disable once UnusedMember.Global // ReSharper disable once UnusedMember.Global
@@ -41,7 +43,7 @@ namespace mROA.Implementation
// ReSharper disable once MemberCanBePrivate.Global // ReSharper disable once MemberCanBePrivate.Global
public T Value public T Value
{ {
get => _value; get => _value!;
set set
{ {
_value = value; _value = value;
@@ -76,11 +78,11 @@ namespace mROA.Implementation
public object UniversalValue public object UniversalValue
{ {
get => _value; get => _value!;
set => _value = (T)value; set => _value = (T)value;
} }
private IContextRepository GetDefaultContextRepository() => private IInstanceRepository GetDefaultContextRepository() =>
(_identifier.OwnerId == EndPointContext.HostId (_identifier.OwnerId == EndPointContext.HostId
? EndPointContext.RealRepository ? EndPointContext.RealRepository
: EndPointContext.RemoteRepository) ?? : EndPointContext.RemoteRepository) ??
-35
View File
@@ -1,35 +0,0 @@
using System;
using mROA.Abstract;
namespace mROA.Implementation
{
#pragma warning disable CS8618, CS9264
public static class TransmissionConfig
{
#if TRACE
public static int TotalTransmittedBytes { get; set; }
#endif
// private static IContextRepository? _realContextRepository;
// private static IContextRepository? _remoteEndpointContextRepository;
// private static IOwnershipRepository? _ownershipRepository;
//
// public static IContextRepository RealContextRepository
// {
// get => _realContextRepository ?? throw new NullReferenceException("RealContextRepository is null");
// set => _realContextRepository = value;
// }
//
// public static IContextRepository RemoteEndpointContextRepository
// {
// get => _remoteEndpointContextRepository ??
// throw new NullReferenceException("RemoteEndpointContextRepository is null");
// set => _remoteEndpointContextRepository = value;
// }
//
// public static IOwnershipRepository OwnershipRepository
// {
// get => _ownershipRepository ?? throw new NullReferenceException("OwnershipRepository is null");
// set => _ownershipRepository = value;
// }
}
}