diff --git a/Example.Backend/LoadTestImp.cs b/Example.Backend/LoadTestImp.cs new file mode 100644 index 0000000..35c698a --- /dev/null +++ b/Example.Backend/LoadTestImp.cs @@ -0,0 +1,14 @@ +using Example.Shared; +using mROA.Implementation; +using mROA.Implementation.Attributes; + +namespace Example.Backend; + +[SharedObjectSingleton] +public class LoadTestImp : ILoadTest +{ + public int Next(int last) + { + return last + 1; + } +} \ No newline at end of file diff --git a/Example.Frontend/Program.cs b/Example.Frontend/Program.cs index deda97b..a8a7c61 100644 --- a/Example.Frontend/Program.cs +++ b/Example.Frontend/Program.cs @@ -1,8 +1,10 @@ // See https://aka.ms/new-console-template for more information +using System.Diagnostics; using System.Net; using System.Text; +using Example.Shared; using mROA.Codegen; using mROA.Implementation.Bootstrap; using mROA.Implementation.Frontend; @@ -20,7 +22,7 @@ mixer.Build(); mixer.GetModule().Connect(); var context = mixer.GetModule(); -var factory = context.GetSingleObject(typeof(Example.Shared.IPrinterFactory)) as Example.Shared.IPrinterFactory; +var factory = context.GetSingleObject(typeof(IPrinterFactory)) as IPrinterFactory; var printer = factory.Create("Test"); @@ -28,4 +30,17 @@ var name = printer.Value.GetName(); Console.WriteLine("Printer name : {0}", name); var page = await printer.Value.Print("Test Page", new CancellationToken()); var data = page.Value.GetData(); -Console.WriteLine("Data : {0}", Encoding.UTF8.GetString(data)); \ No newline at end of file +Console.WriteLine("Data : {0}", Encoding.UTF8.GetString(data)); + +var loadSingleton = context.GetSingleObject(typeof(ILoadTest)) as ILoadTest; + +const int iterations = 10000; +var timer = Stopwatch.StartNew(); +for (int i = 0; i < iterations; i++) +{ + var x = loadSingleton.Next(1); + Console.WriteLine(x); +} +timer.Stop(); + +Console.WriteLine("Time : {0}", timer.Elapsed); \ No newline at end of file diff --git a/Example.Shared/ILoadTest.cs b/Example.Shared/ILoadTest.cs new file mode 100644 index 0000000..f8206bc --- /dev/null +++ b/Example.Shared/ILoadTest.cs @@ -0,0 +1,10 @@ +using mROA.Implementation; +using mROA.Implementation.Attributes; + +namespace Example.Shared; + +[SharedObjectInterface] +public interface ILoadTest +{ + int Next(int last); +} \ No newline at end of file diff --git a/mROA.Codegen/SampleIncrementalSourceGenerator.cs b/mROA.Codegen/SampleIncrementalSourceGenerator.cs index 4c79204..57f635e 100644 --- a/mROA.Codegen/SampleIncrementalSourceGenerator.cs +++ b/mROA.Codegen/SampleIncrementalSourceGenerator.cs @@ -1,7 +1,5 @@ -using System; using System.Collections.Generic; using System.Collections.Immutable; -using System.ComponentModel; using System.Linq; using System.Text; using Microsoft.CodeAnalysis; @@ -181,6 +179,7 @@ using mROA; using System; using mROA.Implementation; using System.Collections.Generic; +using mROA.Abstract; namespace {namespaceName}; @@ -209,6 +208,7 @@ partial class {className} (int id, ISerialisationModule.IFrontendSerialisationMo var coCodegenRepoCode = @$"// using System.Collections.Generic; using System.Reflection; +using mROA.Abstract; namespace mROA.Codegen; @@ -250,6 +250,7 @@ public class CoCodegenMethodRepository :IMethodRepository var fronendRepoCode = @$"// using System.Collections.Frozen; using mROA.Implementation; +using mROA.Abstract; namespace mROA.Codegen; diff --git a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs index 4469387..e5f5b82 100644 --- a/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs +++ b/mROA/Implementation/Frontend/JsonFrontendSerialisationModule.cs @@ -45,7 +45,6 @@ public class JsonFrontendSerialisationModule parsed = JsonSerializer.Deserialize>(receiveMessage)!; } - parsed.Result = parsed.Result! is JsonElement e ? e.Deserialize() : (T)parsed.Result!; return parsed; } diff --git a/mROA/Implementation/TransmittedSharedObject.cs b/mROA/Implementation/TransmittedSharedObject.cs index d577631..6b2228c 100644 --- a/mROA/Implementation/TransmittedSharedObject.cs +++ b/mROA/Implementation/TransmittedSharedObject.cs @@ -14,12 +14,13 @@ public class TransmittedSharedObject where T : notnull throw new NullReferenceException( "DefaultContextRepository was not defined"); - private int ContextId { get; init; } = -1; + // ReSharper disable once MemberCanBePrivate.Global + public int ContextId { get; init; } = -1; [JsonIgnore] public T? Value => GetDefaultContextRepository().GetObject(ContextId); - private TransmittedSharedObject() + public TransmittedSharedObject() { } public TransmittedSharedObject(T value)