From dce374035f6e8f5fefd602517d3df9ddf097cfb3 Mon Sep 17 00:00:00 2001 From: Mikhail Mitrofanov Date: Tue, 7 Jul 2026 22:39:25 +0300 Subject: [PATCH] Caching singleton proxies --- mROA/Implementation/RemoteInstanceRepository.cs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mROA/Implementation/RemoteInstanceRepository.cs b/mROA/Implementation/RemoteInstanceRepository.cs index dec5c9c..fe557d2 100644 --- a/mROA/Implementation/RemoteInstanceRepository.cs +++ b/mROA/Implementation/RemoteInstanceRepository.cs @@ -8,6 +8,7 @@ namespace mROA.Implementation public class RemoteInstanceRepository : IInstanceRepository { private readonly List _producedProxies = new(); + private readonly List _producedSingletonProxies = new(); private readonly ICallIndexProvider _callIndexProvider; private readonly IRepresentationModuleProducer _representationProducer; @@ -32,9 +33,9 @@ namespace mROA.Implementation public T GetObject(ComplexObjectIdentifier id, IEndPointContext context) where T : class { - var index = _producedProxies.Find(i => i.Identifier.Equals(id)); - if (index is not null) - return (T)(index as object); + var existing = _producedProxies.Find(i => i.Identifier.Equals(id)); + if (existing is not null) + return (T)(existing as object); if (!_callIndexProvider.Activators.TryGetValue(typeof(T), out var remoteType)) throw new NotSupportedException(); @@ -55,6 +56,10 @@ namespace mROA.Implementation public object GetSingletonObject(Type type, IEndPointContext context) { + var existing = _producedSingletonProxies.Find(i => i.GetType() == type); + if (existing is not null) + return existing; + var representationModule = _representationProducer.Produce(context.OwnerId); @@ -62,6 +67,7 @@ namespace mROA.Implementation _callIndexProvider.GetIndices(type))!; _producedProxies.Add(instance); + _producedSingletonProxies.Add(instance); return _producedProxies.Last(); }