Skip to content

Commit

Permalink
Merge branch 'main' into Remove_duplicate_versions
Browse files Browse the repository at this point in the history
  • Loading branch information
BalassaMarton authored Oct 12, 2023
2 parents f9c3f19 + a235bab commit 8712037
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,21 @@

namespace MorganStanley.ComposeUI.ModuleLoader;

/// <summary>
/// Represents a collection of modules that can be started in the scope of the application.
/// </summary>
public interface IModuleCatalog
{
/// <summary>
/// Gets a module's manifest by its module ID.
/// </summary>
/// <param name="moduleId"></param>
/// <returns></returns>
IModuleManifest GetManifest(string moduleId);

/// <summary>
/// Gets the IDs of the modules in the catalog.
/// </summary>
/// <returns></returns>
IEnumerable<string> GetModuleIds();
}
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Represents a running instance of a module.
/// </summary>
public interface IModuleInstance
{
/// <summary>
/// Gets the unique ID of the module instance.
/// </summary>
Guid InstanceId { get; }

/// <summary>
/// Gets the manifest of the module.
/// </summary>
IModuleManifest Manifest { get; }

/// <summary>
/// Gets the original <see cref="StartRequest"/> that was used to start the module.
/// </summary>
StartRequest StartRequest { get; }

/// <summary>
/// Gets the properties of type <typeparamref name="T"/> attached to the module instance.
/// </summary>
/// <typeparam name="T">The type of the properties to get</typeparam>
/// <returns>The collection of properties of the specified type, in the order they were added to the <see cref="StartupContext"/></returns>
IEnumerable<T> GetProperties<T>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace MorganStanley.ComposeUI.ModuleLoader;

public interface IModuleLoader
{
void RequestStart(StartRequest startupRequest);
void RequestStart(StartRequest startRequest);

void RequestStop(StopRequest stopRequest);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,11 +20,36 @@ public interface IModuleManifest

string Name { get; }

string StartupType { get; }
string ModuleType { get; }
}

public interface IModuleManifest<out TDetails> : IModuleManifest
{
TDetails GetDetails();
TDetails Details { get; }
}

public static class ModuleManifestExtensions
{
/// <summary>
/// Shorthand for querying a module manifest for a specific details type.
/// </summary>
/// <typeparam name="TDetails">The type of the details</typeparam>
/// <param name="manifest">The module manifest</param>
/// <param name="details">The variable receiving the details object when the operation succeeds (or <c>default</c> otherwise).</param>
/// <returns>
/// True, if <paramref name="manifest"/> implements <see cref="IModuleManifest{TDetails}"/>.
/// </returns>
public static bool TryGetDetails<TDetails>(this IModuleManifest manifest, [NotNullWhen(true)] out TDetails details)
{
if (manifest is IModuleManifest<TDetails> manifestDetails)
{
details = manifestDetails.Details!;

return true;
}

details = default!;

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Contains the predefined module types.
/// </summary>
public static class ModuleType
{
public const string Native = "native";
public const string Web = "web";
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ namespace MorganStanley.ComposeUI.ModuleLoader;

public sealed class StartRequest
{
public StartRequest(string moduleId)
public StartRequest(
string moduleId,
IEnumerable<KeyValuePair<string, string>>? parameters = null)
{
ModuleId = moduleId;
InstanceId = Guid.NewGuid();
Parameters = parameters?.ToArray() ?? Array.Empty<KeyValuePair<string, string>>();
}

public Guid InstanceId { get; }

public string ModuleId { get; }

public KeyValuePair<string, string>[] Parameters { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Contains the manifest details for web modules.
/// </summary>
/// <remarks>
/// Web modules should have <see cref="ModuleType.Web"/> as their <see cref="IModuleManifest.ModuleType"/>
/// </remarks>
public sealed class WebManifestDetails
{
/// <summary>
/// The URL to open when this module is started.
/// </summary>
public Uri Url { get; init; }

/// <summary>
/// The URL of the window icon, if any.
/// </summary>
public Uri? IconUrl { get; init; }
}
Original file line number Diff line number Diff line change
@@ -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;

/// <summary>
/// Contains the necessary properties to start a web module.
/// This type is injected to <see cref="StartupContext"/>.
/// </summary>
public sealed class WebStartupProperties
{
public Uri Url { get; set; }
public Uri? IconUrl { get; set; }
}

0 comments on commit 8712037

Please sign in to comment.