Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 66 additions & 64 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions src/fdc3/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<Import Project="../Directory.Build.props" Condition="Exists('../Directory.Build.props')" />
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection;

public class Fdc3DesktopAgentBuilder
{
public IServiceCollection ServiceCollection { get; }

public Fdc3DesktopAgentBuilder(IServiceCollection serviceCollection)
{
ServiceCollection = serviceCollection;
}

/// <summary>
/// Method, for configuring `Fdc3Options` from full `IConfiguration` by searching for section `Fdc3Options.Fdc3OptionsName`.
/// </summary>
/// <typeparam name="TOptions">Must be Fdc3Options reference type.</typeparam>
/// <param name="configuration">Full IConfigration passed from the Application.</param>
/// <returns></returns>
public Fdc3DesktopAgentBuilder Configure<TOptions>(IConfiguration configuration)
where TOptions : class, IOptions<Fdc3Options>
{
ServiceCollection.Configure<TOptions>(configuration.GetSection(Fdc3Options.Fdc3OptionsName));

return this;
}

/// <summary>
/// Extension method, for configuring the `Fdc3Options` by `Action`.
/// </summary>
/// <param name="configureOptions"></param>
/// <returns></returns>
public Fdc3DesktopAgentBuilder Configure(Action<Fdc3Options> configureOptions)
{
ServiceCollection.AddOptions<Fdc3Options>()
.Configure(configureOptions);

return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,23 @@
* and limitations under the License.
*/

using Microsoft.Extensions.Options;

namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection;

public class Fdc3DesktopAgentConfig
public sealed class Fdc3Options : IOptions<Fdc3Options>
{
internal List<Func<Fdc3DesktopAgent, ValueTask>> BuilderActions { get; } = new();
public static readonly string Fdc3OptionsName = "Fdc3Options";

/// <summary>
/// When set to <value>true</value>, it will enable Fdc3 backend service.
/// </summary>
public bool EnableFdc3 { get; set; }

/// <summary>
/// When set to any value, it will start the DesktopAgent with passing the value to the `WithUserChannel` builder action.
/// </summary>
public string? ChannelId { get; set; }

public Fdc3DesktopAgentConfig WithUserChannel(string channelId)
{
BuilderActions.Add(fdc3 => fdc3.AddUserChannel(channelId));
return this;
}
Fdc3Options IOptions<Fdc3Options>.Value => this;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* and limitations under the License.
*/

using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection;
Expand All @@ -22,15 +23,41 @@ public static class ServiceCollectionExtensions
{
public static IServiceCollection AddFdc3DesktopAgent(
this IServiceCollection serviceCollection,
Action<Fdc3DesktopAgentConfig>? builderAction = null)
Action<Fdc3DesktopAgentBuilder>? builderAction = null)
{
var config = new Fdc3DesktopAgentConfig();
var builder = new Fdc3DesktopAgentBuilder(serviceCollection);

if (builderAction != null)
{
builderAction(config);
builderAction(builder);
}
serviceCollection.AddSingleton(config);

serviceCollection.AddSingleton<IHostedService, Fdc3DesktopAgent>();
return serviceCollection;
}

/// <summary>
/// Checks the configuration, if that contains Fdc3Options part, where the user could set the EnableFdc3 tag to true.
/// If that tag value is true, it will add the DesktopAgent service to the ServiceCollection, with the given Fdc3Options, that was set in the configuration.
/// </summary>
/// <param name="serviceCollection"></param>
/// <param name="configuration">This should be the IConfigurationSection, which contains the configuration for Fdc3.</param>
/// <param name="builderAction"></param>
/// <returns></returns>
public static IServiceCollection InjectFdc3BackendServiceIfEnabledFromConfig(
this IServiceCollection serviceCollection,
IConfiguration configuration,
Action<Fdc3DesktopAgentBuilder>? builderAction = null)
{
var fdc3Options = configuration.Get<Fdc3Options>();

//TODO: This should be feature toggle, once we have feature toggles in the future - instead of having `EnableFdc3` inside Fdc3Options.
if (fdc3Options.EnableFdc3)
{
serviceCollection.Configure<Fdc3Options>(configuration);
serviceCollection.AddFdc3DesktopAgent(builderAction);
}

return serviceCollection;
}
}
34 changes: 17 additions & 17 deletions src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/DesktopAgent.csproj
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>MorganStanley.ComposeUI.Fdc3.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>MorganStanley.ComposeUI.Fdc3.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<AssemblyName>MorganStanley.ComposeUI.Fdc3.$(MSBuildProjectName)</AssemblyName>
<RootNamespace>MorganStanley.ComposeUI.Fdc3.$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
<PackageReference Include="MorganStanley.Fdc3" Version="2.0.0-alpha.5" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.4" />
<PackageReference Include="MorganStanley.Fdc3" Version="2.0.0-alpha.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\messaging\dotnet\src\Core\MorganStanley.ComposeUI.Messaging.Core.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\..\..\..\messaging\dotnet\src\Core\MorganStanley.ComposeUI.Messaging.Core.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.Extensions.Options;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.Contracts;
using MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection;
using MorganStanley.ComposeUI.Messaging;
Expand All @@ -27,14 +28,17 @@ public class Fdc3DesktopAgent : IHostedService
private readonly List<UserChannel> _userChannels = new();

private readonly ILoggerFactory _loggerFactory;
private readonly Fdc3Options _options;
private readonly IMessageRouter _messageRouter;
private Fdc3DesktopAgentConfig? _config;

public Fdc3DesktopAgent(IMessageRouter messageRouter, ILoggerFactory? loggerFactory, Fdc3DesktopAgentConfig? config)
public Fdc3DesktopAgent(
IOptions<Fdc3Options> options,
IMessageRouter messageRouter,
ILoggerFactory? loggerFactory = null)
{
_options = options.Value;
_messageRouter = messageRouter;
_loggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
_config = config;
}

public async ValueTask AddUserChannel(string id)
Expand All @@ -61,19 +65,9 @@ public async Task StartAsync(CancellationToken cancellationToken)
{
await _messageRouter.RegisterServiceAsync(Fdc3Topic.FindChannel, FindChannel);

if (_config == null)
{
return;
}

// There are no dependencies among possible actions at the moment.
// Future features may introduce dependencies, in that case this solution needs to change
foreach (var task in _config.BuilderActions.Select(x => x(this)).ToArray())
{
await (task);
}
if (_options.ChannelId == null) return;

_config = null;
await AddUserChannel(_options.ChannelId);
}

public async Task StopAsync(CancellationToken cancellationToken)
Expand Down
Loading