From 6afb5d77634f248c6afea6b0f5d440b31d94501b Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Sun, 16 Oct 2022 10:21:23 +0200 Subject: [PATCH] basic design questions --- src/ServiceComposer.InMemory.Tests/Sample.cs | 47 +++++++++++++++++++ .../ServiceComposer.InMemory.Tests.csproj | 27 +++++++++++ src/ServiceComposer.InMemory.sln | 6 +++ 3 files changed, 80 insertions(+) create mode 100644 src/ServiceComposer.InMemory.Tests/Sample.cs create mode 100644 src/ServiceComposer.InMemory.Tests/ServiceComposer.InMemory.Tests.csproj diff --git a/src/ServiceComposer.InMemory.Tests/Sample.cs b/src/ServiceComposer.InMemory.Tests/Sample.cs new file mode 100644 index 0000000..2cf9240 --- /dev/null +++ b/src/ServiceComposer.InMemory.Tests/Sample.cs @@ -0,0 +1,47 @@ +using Microsoft.Extensions.DependencyInjection; +using Xunit; + +namespace ServiceComposer.InMemory.Tests +{ + public class Sample + { + class Handler : ICompositionRequestsHandler + { + public Task Handle(ICompositionContext context) + { + // how to access the view model? Using the same GetComposedResponseModel + // as in Asp.NetCore but on the contenxt? e.g.: + //var vm = context.GetComposedResponseModel(); + + // should te default view model be the usual dynamic object? + + return Task.CompletedTask; + } + } + + [Fact] + public async Task Should_run() + { + // In a console app the following would be the minimum + // required configuration. Given that there is no "run" + // phase, there is no place to initialize the composition + // engine. + // One option is to do that when adding stuff to the ServiceCollection + // Another option woul dbe to require usage of the Host and register a + // HostedService that does te heavy lifting when the application host + // starts. + + var services = new ServiceCollection(); + services.AddInMemoryViewModelComposition(options => + { + options.AssemblyScanner.Disable(); + options.RegisterCompositionHandler(); + }); + + var serviceProvider = services.BuildServiceProvider(); + var compositionEngine = serviceProvider.GetRequiredService(); + + var composedViewModel = await compositionEngine.HandleComposableRequest("a/request"); + } + } +} \ No newline at end of file diff --git a/src/ServiceComposer.InMemory.Tests/ServiceComposer.InMemory.Tests.csproj b/src/ServiceComposer.InMemory.Tests/ServiceComposer.InMemory.Tests.csproj new file mode 100644 index 0000000..111b512 --- /dev/null +++ b/src/ServiceComposer.InMemory.Tests/ServiceComposer.InMemory.Tests.csproj @@ -0,0 +1,27 @@ + + + + net6.0 + enable + enable + false + + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers + + + + + + + + diff --git a/src/ServiceComposer.InMemory.sln b/src/ServiceComposer.InMemory.sln index f1efa0d..b0a0c06 100644 --- a/src/ServiceComposer.InMemory.sln +++ b/src/ServiceComposer.InMemory.sln @@ -4,6 +4,8 @@ VisualStudioVersion = 17.0.31912.275 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceComposer.InMemory", "ServiceComposer.InMemory\ServiceComposer.InMemory.csproj", "{5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServiceComposer.InMemory.Tests", "ServiceComposer.InMemory.Tests\ServiceComposer.InMemory.Tests.csproj", "{576936D7-A7C4-40A7-B87B-E759B80C09DF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -14,6 +16,10 @@ Global {5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}.Debug|Any CPU.Build.0 = Debug|Any CPU {5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}.Release|Any CPU.ActiveCfg = Release|Any CPU {5D70C2D3-7F78-48E6-8EB9-BC8E85B850D1}.Release|Any CPU.Build.0 = Release|Any CPU + {576936D7-A7C4-40A7-B87B-E759B80C09DF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {576936D7-A7C4-40A7-B87B-E759B80C09DF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {576936D7-A7C4-40A7-B87B-E759B80C09DF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {576936D7-A7C4-40A7-B87B-E759B80C09DF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE