diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleCatalog.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleCatalog.cs index 28ba862a4..ded23272f 100644 --- a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleCatalog.cs +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleCatalog.cs @@ -12,9 +12,21 @@ namespace MorganStanley.ComposeUI.ModuleLoader; +/// +/// Represents a collection of modules that can be started in the scope of the application. +/// public interface IModuleCatalog { + /// + /// Gets a module's manifest by its module ID. + /// + /// + /// IModuleManifest GetManifest(string moduleId); + /// + /// Gets the IDs of the modules in the catalog. + /// + /// IEnumerable GetModuleIds(); } diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleInstance.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleInstance.cs new file mode 100644 index 000000000..2924f44f1 --- /dev/null +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleInstance.cs @@ -0,0 +1,41 @@ +// Morgan Stanley makes this available to you under the Apache License, +// Version 2.0 (the "License"). You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0. +// +// See the NOTICE file distributed with this work for additional information +// regarding copyright ownership. Unless required by applicable law or agreed +// to in writing, software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions +// and limitations under the License. + +namespace MorganStanley.ComposeUI.ModuleLoader; + +/// +/// Represents a running instance of a module. +/// +public interface IModuleInstance +{ + /// + /// Gets the unique ID of the module instance. + /// + Guid InstanceId { get; } + + /// + /// Gets the manifest of the module. + /// + IModuleManifest Manifest { get; } + + /// + /// Gets the original that was used to start the module. + /// + StartRequest StartRequest { get; } + + /// + /// Gets the properties of type attached to the module instance. + /// + /// The type of the properties to get + /// The collection of properties of the specified type, in the order they were added to the + IEnumerable GetProperties(); +} \ No newline at end of file diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleLoader.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleLoader.cs index 91c97f4ba..66f879e2d 100644 --- a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleLoader.cs +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleLoader.cs @@ -14,7 +14,7 @@ namespace MorganStanley.ComposeUI.ModuleLoader; public interface IModuleLoader { - void RequestStart(StartRequest startupRequest); + void RequestStart(StartRequest startRequest); void RequestStop(StopRequest stopRequest); diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleManifest.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleManifest.cs index 63d041610..f3ad6ffea 100644 --- a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleManifest.cs +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/IModuleManifest.cs @@ -10,6 +10,8 @@ // or implied. See the License for the specific language governing permissions // and limitations under the License. +using System.Diagnostics.CodeAnalysis; + namespace MorganStanley.ComposeUI.ModuleLoader; public interface IModuleManifest @@ -18,11 +20,36 @@ public interface IModuleManifest string Name { get; } - string StartupType { get; } + string ModuleType { get; } } public interface IModuleManifest : IModuleManifest { - TDetails GetDetails(); + TDetails Details { get; } } +public static class ModuleManifestExtensions +{ + /// + /// Shorthand for querying a module manifest for a specific details type. + /// + /// The type of the details + /// The module manifest + /// The variable receiving the details object when the operation succeeds (or default otherwise). + /// + /// True, if implements . + /// + public static bool TryGetDetails(this IModuleManifest manifest, [NotNullWhen(true)] out TDetails details) + { + if (manifest is IModuleManifest manifestDetails) + { + details = manifestDetails.Details!; + + return true; + } + + details = default!; + + return false; + } +} \ No newline at end of file diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs index 08790c75d..a803034c1 100644 --- a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/LifetimeEvent.cs @@ -14,68 +14,60 @@ namespace MorganStanley.ComposeUI.ModuleLoader; public abstract class LifetimeEvent { - protected LifetimeEvent(Guid instanceId) + protected LifetimeEvent(IModuleInstance instance) { - InstanceId = instanceId; + Instance = instance; } - public Guid InstanceId { get; } - + public IModuleInstance Instance { get; } public abstract LifetimeEventType EventType { get; } public sealed class Starting : LifetimeEvent { - internal Starting(Guid instanceId) - : base(instanceId) - { } + public Starting(IModuleInstance instance) : base(instance) + { + } public override LifetimeEventType EventType => LifetimeEventType.Starting; } public sealed class Started : LifetimeEvent { - internal Started(Guid instanceId) - : base(instanceId) - { } + public Started(IModuleInstance instance) : base(instance) + { + } public override LifetimeEventType EventType => LifetimeEventType.Started; } public sealed class Stopping : LifetimeEvent { - internal Stopping(Guid instanceId) - : base(instanceId) - { } + public Stopping(IModuleInstance instance) : base(instance) + { + } public override LifetimeEventType EventType => LifetimeEventType.Stopping; } public sealed class Stopped : LifetimeEvent { - internal Stopped(Guid instanceId, bool isExpected = true) - : base(instanceId) + public Stopped( + IModuleInstance instance, + bool isExpected = true) : base(instance) { IsExpected = isExpected; } public override LifetimeEventType EventType => LifetimeEventType.Stopped; - public bool IsExpected { get; set; } + public bool IsExpected { get; } } } - - - - - - - - public enum LifetimeEventType { Starting, Started, Stopping, Stopped -} \ No newline at end of file +} diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/ModuleType.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/ModuleType.cs new file mode 100644 index 000000000..cc45ba965 --- /dev/null +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/ModuleType.cs @@ -0,0 +1,22 @@ +// Morgan Stanley makes this available to you under the Apache License, +// Version 2.0 (the "License"). You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0. +// +// See the NOTICE file distributed with this work for additional information +// regarding copyright ownership. Unless required by applicable law or agreed +// to in writing, software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions +// and limitations under the License. + +namespace MorganStanley.ComposeUI.ModuleLoader; + +/// +/// Contains the predefined module types. +/// +public static class ModuleType +{ + public const string Native = "native"; + public const string Web = "web"; +} diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj index 7453cbdcd..d609e871c 100644 --- a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj @@ -1,4 +1,4 @@ - + net6.0 diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs index 2408f60fe..a4fb3da49 100644 --- a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StartRequest.cs @@ -14,13 +14,15 @@ namespace MorganStanley.ComposeUI.ModuleLoader; public sealed class StartRequest { - public StartRequest(string moduleId) + public StartRequest( + string moduleId, + IEnumerable>? parameters = null) { ModuleId = moduleId; - InstanceId = Guid.NewGuid(); + Parameters = parameters?.ToArray() ?? Array.Empty>(); } - public Guid InstanceId { get; } - public string ModuleId { get; } + + public KeyValuePair[] Parameters { get; } } diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StopRequest.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StopRequest.cs index a2faa08f3..e73b4e0c9 100644 --- a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StopRequest.cs +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/StopRequest.cs @@ -12,7 +12,12 @@ namespace MorganStanley.ComposeUI.ModuleLoader; -public struct StopRequest +public sealed class StopRequest { - public Guid InstanceId; + public StopRequest(Guid instanceId) + { + InstanceId = instanceId; + } + + public Guid InstanceId { get; } } diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/WebManifestDetails.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/WebManifestDetails.cs new file mode 100644 index 000000000..dfabef376 --- /dev/null +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/WebManifestDetails.cs @@ -0,0 +1,32 @@ +// Morgan Stanley makes this available to you under the Apache License, +// Version 2.0 (the "License"). You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0. +// +// See the NOTICE file distributed with this work for additional information +// regarding copyright ownership. Unless required by applicable law or agreed +// to in writing, software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions +// and limitations under the License. + +namespace MorganStanley.ComposeUI.ModuleLoader; + +/// +/// Contains the manifest details for web modules. +/// +/// +/// Web modules should have as their +/// +public sealed class WebManifestDetails +{ + /// + /// The URL to open when this module is started. + /// + public Uri Url { get; init; } + + /// + /// The URL of the window icon, if any. + /// + public Uri? IconUrl { get; init; } +} diff --git a/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/WebStartupProperties.cs b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/WebStartupProperties.cs new file mode 100644 index 000000000..3b724d6c7 --- /dev/null +++ b/src/module-loader/dotnet/src/MorganStanley.ComposeUI.ModuleLoader.Abstractions/WebStartupProperties.cs @@ -0,0 +1,23 @@ +// Morgan Stanley makes this available to you under the Apache License, +// Version 2.0 (the "License"). You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0. +// +// See the NOTICE file distributed with this work for additional information +// regarding copyright ownership. Unless required by applicable law or agreed +// to in writing, software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +// or implied. See the License for the specific language governing permissions +// and limitations under the License. + +namespace MorganStanley.ComposeUI.ModuleLoader; + +/// +/// Contains the necessary properties to start a web module. +/// This type is injected to . +/// +public sealed class WebStartupProperties +{ + public Uri Url { get; set; } + public Uri? IconUrl { get; set; } +} \ No newline at end of file