Semi-ready client DI rewrite

This commit is contained in:
2025-07-12 14:07:26 +03:00
parent 3947961d22
commit 1b9a521c46
4 changed files with 46 additions and 33 deletions
-1
View File
@@ -52,7 +52,6 @@ class Program
var mroaMachine = builder.Build();
mroaMachine.StartAsync();
//
// builder.Build();
// new RemoteTypeBinder();
+38 -24
View File
@@ -6,12 +6,13 @@ using System.Threading;
using System.Threading.Tasks;
using Example.Frontend;
using Example.Shared;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using mROA.Abstract;
using mROA.Cbor;
using mROA.Codegen;
using mROA.Implementation;
using mROA.Implementation.Backend;
using mROA.Implementation.Bootstrap;
using mROA.Implementation.Frontend;
@@ -21,38 +22,51 @@ class Program
{
new RemoteTypeBinder();
var builder = Host.CreateApplicationBuilder();
builder.Services.AddSingleton<IContextualSerializationToolKit, CborSerializationToolkit>();
builder.Services.AddSingleton<IEndPointContext, EndPointContext>();
builder.Services.AddSingleton<IRealStoreInstanceRepository, InstanceRepository>(provider =>
{
var repo = new InstanceRepository(provider.GetService<IRepresentationModuleProducer>());
repo.FillSingletons(typeof(Program).Assembly);
return repo;
});
builder.Modules.Add(new CborSerializationToolkit());
builder.Modules.Add(new EndPointContext());
builder.Modules.Add(new RemoteInstanceRepository());
builder.Modules.Add(new ChannelInteractionModule());
builder.Modules.Add(new UdpUntrustedInteraction());
builder.Modules.Add(new RepresentationModule());
builder.Services.AddSingleton<IInstanceRepository, RemoteInstanceRepository>();
builder.Services.AddSingleton<IChannelInteractionModule, ChannelInteractionModule>();
builder.Services.AddSingleton<IUntrustedInteractionModule, UdpUntrustedInteraction>();
builder.Services.AddSingleton<IRepresentationModule, RepresentationModule>();
var serverEndPoint = new IPEndPoint(IPAddress.Loopback, 4567);
builder.Modules.Add(new NetworkFrontendBridge(serverEndPoint));
builder.Modules.Add(new StaticRepresentationModuleProducer());
builder.Modules.Add(new RequestExtractor());
builder.Modules.Add(new BasicExecutionModule());
builder.Services.AddSingleton<IFrontendBridge, NetworkFrontendBridge>();
builder.Services.AddOptions();
builder.Services.Configure<GatewayOptions>(options => options.Endpoint = serverEndPoint);
builder.Services.AddSingleton<IRepresentationModuleProducer, StaticRepresentationModuleProducer>();
builder.Services.AddSingleton<IRequestExtractor, RequestExtractor>();
builder.Services.AddSingleton<IExecuteModule, BasicExecutionModule>();
builder.Services.AddSingleton<IMethodRepository, CollectableMethodRepository>(p =>
{
var methodRepo = new CollectableMethodRepository();
methodRepo.AppendInvokers(new GeneratedInvokersCollection());
builder.Modules.Add(methodRepo);
builder.Modules.Add(new GeneratedCallIndexProvider());
builder.UseCollectableContextRepository();
builder.Modules.Add(new CancellationRepository());
return methodRepo;
});
builder.Services.AddSingleton<ICallIndexProvider, GeneratedCallIndexProvider>();
builder.Services.AddSingleton<ICancellationRepository, CancellationRepository>();
builder.Build();
var app = builder.Build();
var frontendBridge = builder.GetModule<IFrontendBridge>()!;
var frontendBridge = app.Services.GetService<IFrontendBridge>()!;
await frontendBridge.Connect();
_ = builder.GetModule<RequestExtractor>()!.StartExtraction();
_ = builder.GetModule<UdpUntrustedInteraction>().Start(serverEndPoint);
Console.WriteLine(builder.GetModule<IEndPointContext>().HostId);
var context = builder.GetModule<RemoteInstanceRepository>();
_ = app.Services.GetService<RequestExtractor>()!.StartExtraction();
_ = app.Services.GetService<UdpUntrustedInteraction>().Start(serverEndPoint);
Console.WriteLine(app.Services.GetService<IEndPointContext>().HostId);
var context = app.Services.GetService<RemoteInstanceRepository>();
#if !JUST_LOAD
#if !JUST_LOAD
var factory =
context.GetSingletonObject<IPrinterFactory>(
builder.GetModule<IEndPointContext>());
app.Services.GetService<IEndPointContext>());
using (var disposingPrinter = factory.Create("Test"))
{
@@ -118,7 +132,7 @@ class Program
DemoCheck.Dispose = true;
#endif
var loadSingleton = context.GetSingletonObject<ILoadTest>(builder.GetModule<IEndPointContext>());
var loadSingleton = context.GetSingletonObject<ILoadTest>(app.Services.GetService<IEndPointContext>());
#if !JUST_LOAD
var cts = new CancellationTokenSource();
@@ -3,7 +3,9 @@ using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using mROA.Abstract;
using mROA.Implementation.Backend;
using Exception = System.Exception;
namespace mROA.Implementation.Frontend
@@ -18,9 +20,9 @@ namespace mROA.Implementation.Frontend
private CancellationTokenSource _rawExtractorCancellation;
private IEndPointContext _context;
public NetworkFrontendBridge(IPEndPoint serverEndPoint, IEndPointContext context, IContextualSerializationToolKit serialization)
public NetworkFrontendBridge(IOptions<GatewayOptions> options, IEndPointContext context, IContextualSerializationToolKit serialization)
{
_serverEndPoint = serverEndPoint;
_serverEndPoint = options.Value.Endpoint;
_context = context;
_serialization = serialization;
_rawExtractorCancellation = new CancellationTokenSource();
@@ -14,8 +14,6 @@ namespace mROA.Implementation
public IRepresentationModule Produce(int ownership)
{
if (_representationModule == null)
throw new NullReferenceException("The representation module is not initialized.");
return _representationModule;
}
}