добавлен мультиклиентский репозиторий
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
namespace mROA.Abstract;
|
||||
|
||||
public interface IContextRepositoryHub
|
||||
{
|
||||
IContextRepository GetRepository(int clientId);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
using mROA.Abstract;
|
||||
|
||||
namespace mROA.Implementation.Backend;
|
||||
|
||||
public class MultiClientContextRepository(Func<int, IContextRepository> produceRepository) : IContextRepository, IContextRepositoryHub
|
||||
{
|
||||
private Dictionary<int, IContextRepository> _repositories = new();
|
||||
|
||||
private IContextRepository GetRepositoryByClientId(int clientId)
|
||||
{
|
||||
if (_repositories.TryGetValue(clientId, out var repository))
|
||||
return repository;
|
||||
|
||||
var created = produceRepository(clientId);
|
||||
_repositories.Add(clientId, created);
|
||||
return created;
|
||||
}
|
||||
public void Inject<T>(T dependency)
|
||||
{
|
||||
}
|
||||
|
||||
public int ResisterObject(object o)
|
||||
{
|
||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).ResisterObject(o);
|
||||
}
|
||||
|
||||
public void ClearObject(int id)
|
||||
{
|
||||
GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).ClearObject(id);
|
||||
}
|
||||
|
||||
public object GetObject(int id)
|
||||
{
|
||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetObject(id);
|
||||
}
|
||||
|
||||
public T? GetObject<T>(int id)
|
||||
{
|
||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetObject<T>(id);
|
||||
}
|
||||
|
||||
public object GetSingleObject(Type type)
|
||||
{
|
||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetSingleObject(type);
|
||||
}
|
||||
|
||||
public int GetObjectIndex(object o)
|
||||
{
|
||||
return GetRepositoryByClientId(TransmissionConfig.OwnershipRepository.GetOwnershipId()).GetObjectIndex(o);
|
||||
}
|
||||
|
||||
public IContextRepository GetRepository(int clientId)
|
||||
{
|
||||
return _repositories[clientId];
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,28 @@ namespace mROA.Implementation;
|
||||
|
||||
public static class TransmissionConfig
|
||||
{
|
||||
public static IContextRepository? RealContextRepository { get; set; }
|
||||
public static IContextRepository? RemoteEndpointContextRepository { get; set; }
|
||||
public static IOwnershipRepository? OwnershipRepository { get; set; }
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class SharedObject<T> where T : notnull
|
||||
|
||||
Reference in New Issue
Block a user