Skip to content

Commit

Permalink
Merge pull request #373 from ztanczos/ModuleLoader.Abstractions
Browse files Browse the repository at this point in the history
Create ModuleLoader.Abstractions
  • Loading branch information
ztanczos authored Oct 10, 2023
2 parents 90e0865 + f05a0b5 commit cd6f50b
Show file tree
Hide file tree
Showing 13 changed files with 406 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/module-loader/dotnet/ModuleLoader.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34031.279
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{0991543E-FA51-4D1C-8756-F6D6FD64C612}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{95B79432-5E5D-4889-8719-D610D6CCC35E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorganStanley.ComposeUI.ModuleLoader.Abstractions", "src\MorganStanley.ComposeUI.ModuleLoader.Abstractions\MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj", "{841D9BAC-DEE6-4E1A-A577-25B20633B110}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MorganStanley.ComposeUI.ModuleLoader.Abstractions.Tests", "tests\MorganStanley.ComposeUI.ModuleLoader.Abstractions.Tests\MorganStanley.ComposeUI.ModuleLoader.Abstractions.Tests.csproj", "{81B6905B-EE74-4387-A5EB-11271A4458A4}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Debug|Any CPU.Build.0 = Debug|Any CPU
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Release|Any CPU.ActiveCfg = Release|Any CPU
{841D9BAC-DEE6-4E1A-A577-25B20633B110}.Release|Any CPU.Build.0 = Release|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{81B6905B-EE74-4387-A5EB-11271A4458A4}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{841D9BAC-DEE6-4E1A-A577-25B20633B110} = {0991543E-FA51-4D1C-8756-F6D6FD64C612}
{81B6905B-EE74-4387-A5EB-11271A4458A4} = {95B79432-5E5D-4889-8719-D610D6CCC35E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {147A1BDA-77DE-4D1A-B8D5-6E8803E11F47}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// 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;

public interface IModuleCatalog
{
IModuleManifest GetManifest(string moduleId);

IEnumerable<string> GetModuleIds();
}
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;

public interface IModuleLoader
{
void RequestStart(StartRequest startupRequest);

void RequestStop(StopRequest stopRequest);

IObservable<LifetimeEvent> LifetimeEvents { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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;

public interface IModuleManifest
{
string Id { get; }

string Name { get; }

string StartupType { get; }
}

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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;

public interface IStartupAction
{
Task InvokeAsync(StartupContext startupContext, Func<Task> next);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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;

public abstract class LifetimeEvent
{
protected LifetimeEvent(Guid instanceId)
{
InstanceId = instanceId;
}

public Guid InstanceId { get; }

public abstract LifetimeEventType EventType { get; }

public sealed class Starting : LifetimeEvent
{
internal Starting(Guid instanceId)
: base(instanceId)
{ }

public override LifetimeEventType EventType => LifetimeEventType.Starting;
}

public sealed class Started : LifetimeEvent
{
internal Started(Guid instanceId)
: base(instanceId)
{ }

public override LifetimeEventType EventType => LifetimeEventType.Started;
}

public sealed class Stopping : LifetimeEvent
{
internal Stopping(Guid instanceId)
: base(instanceId)
{ }

public override LifetimeEventType EventType => LifetimeEventType.Stopping;
}

public sealed class Stopped : LifetimeEvent
{
internal Stopped(Guid instanceId, bool isExpected = true)
: base(instanceId)
{
IsExpected = isExpected;
}

public override LifetimeEventType EventType => LifetimeEventType.Stopped;

public bool IsExpected { get; set; }
}
}









public enum LifetimeEventType
{
Starting,
Started,
Stopping,
Stopped
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>MorganStanley.ComposeUI.ModuleLoader</RootNamespace>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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;

public sealed class StartRequest
{
public StartRequest(string moduleId)
{
ModuleId = moduleId;
InstanceId = Guid.NewGuid();
}

public Guid InstanceId { get; }

public string ModuleId { get; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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.

using System.Collections.Concurrent;
using System.Collections.Immutable;

namespace MorganStanley.ComposeUI.ModuleLoader;

public sealed class StartupContext
{
private readonly ConcurrentDictionary<Type, ImmutableList<object>> _properties = new();

public StartupContext(StartRequest startRequest)
{
StartRequest = startRequest;
}

public StartRequest StartRequest { get; }

public void AddProperty<T>(T value)
{
ArgumentNullException.ThrowIfNull(value, nameof(value));

_properties.AddOrUpdate(typeof(T),
(_) => ImmutableList<object>.Empty.Add(value),
(_, list) => list.Add(value));
}

public IEnumerable<T> GetProperties<T>()
{
if (!_properties.TryGetValue(typeof(T), out var list))
{
return Enumerable.Empty<T>();
}

return list.OfType<T>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// 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;

public struct StopRequest
{
public Guid InstanceId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// 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.

global using Xunit;
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\MorganStanley.ComposeUI.ModuleLoader.Abstractions\MorganStanley.ComposeUI.ModuleLoader.Abstractions.csproj" />
</ItemGroup>

</Project>
Loading

0 comments on commit cd6f50b

Please sign in to comment.