Skip to content

Commit 0aa0317

Browse files
committed
Resolved PR feedback comments
1 parent 598968e commit 0aa0317

File tree

6 files changed

+25
-36
lines changed

6 files changed

+25
-36
lines changed

src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/DependencyInjection/Fdc3DesktopAgentBuilder.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
* and limitations under the License.
1313
*/
1414

15+
using Microsoft.Extensions.Configuration;
1516
using Microsoft.Extensions.DependencyInjection;
17+
using Microsoft.Extensions.Options;
1618

1719
namespace MorganStanley.ComposeUI.Fdc3.DesktopAgent.DependencyInjection;
1820

@@ -25,20 +27,17 @@ public Fdc3DesktopAgentBuilder(IServiceCollection serviceCollection)
2527
ServiceCollection = serviceCollection;
2628
}
2729

28-
public Fdc3DesktopAgentBuilder WithUserChannel(string channelId)
30+
public Fdc3DesktopAgentBuilder Configure<T>(IConfiguration configuration) where T : IOptions<Fdc3Options>
2931
{
30-
ServiceCollection.Configure<Fdc3Options>(config =>
31-
{
32-
config.BuilderActions.Add(fdc3 => fdc3.AddUserChannel(channelId));
33-
});
32+
ServiceCollection.Configure<Fdc3Options>(configuration.GetSection(Fdc3Options.Fdc3OptionsName));
3433

3534
return this;
3635
}
3736

38-
public Fdc3DesktopAgentBuilder Configure(Action<Fdc3Options> confiureOptions)
37+
public Fdc3DesktopAgentBuilder Configure(Action<Fdc3Options> configureOptions)
3938
{
4039
ServiceCollection.AddOptions<Fdc3Options>()
41-
.Configure(confiureOptions);
40+
.Configure(configureOptions);
4241

4342
return this;
4443
}

src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/DependencyInjection/Fdc3Options.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ public sealed class Fdc3Options : IOptions<Fdc3Options>
2020
{
2121
public static readonly string Fdc3OptionsName = "Fdc3Options";
2222

23-
internal List<Func<Fdc3DesktopAgent, ValueTask>> BuilderActions { get; } = new();
24-
2523
/// <summary>
2624
/// When set to <value>true</value>, it will enable Fdc3 backend service.
2725
/// </summary>

src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/DependencyInjection/ServiceCollectionExtensions.cs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ public static IServiceCollection AddFdc3DesktopAgent(
2525
this IServiceCollection serviceCollection,
2626
Action<Fdc3DesktopAgentBuilder>? builderAction = null)
2727
{
28-
var config = new Fdc3DesktopAgentBuilder(serviceCollection);
28+
var builder = new Fdc3DesktopAgentBuilder(serviceCollection);
2929

3030
if (builderAction != null)
3131
{
32-
builderAction(config);
32+
builderAction(builder);
3333
}
3434

35-
serviceCollection.AddSingleton(config);
3635
serviceCollection.AddSingleton<IHostedService, Fdc3DesktopAgent>();
3736
return serviceCollection;
3837
}
@@ -42,23 +41,20 @@ public static IServiceCollection AddFdc3DesktopAgent(
4241
/// 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.
4342
/// </summary>
4443
/// <param name="serviceCollection"></param>
45-
/// <param name="configuration"></param>
44+
/// <param name="configuration">This should be the IConfigurationSection, which contains the configuration for Fdc3.</param>
4645
/// <param name="builderAction"></param>
4746
/// <returns></returns>
4847
public static IServiceCollection InjectFdc3BackendServiceIfEnabledFromConfig(
4948
this IServiceCollection serviceCollection,
5049
IConfiguration configuration,
5150
Action<Fdc3DesktopAgentBuilder>? builderAction = null)
5251
{
53-
var fdc3Options = new Fdc3Options();
54-
55-
var fdc3Configuration = configuration.GetSection(Fdc3Options.Fdc3OptionsName);
56-
57-
fdc3Configuration.Bind(fdc3Options);
52+
var fdc3Options = ConfigurationBinder.Get<Fdc3Options>(configuration);
5853

54+
//TODO: This should be feature toggle, once we have feature toggles in the future - instead of having `EnableFdc3` inside Fdc3Options.
5955
if (fdc3Options.EnableFdc3)
6056
{
61-
serviceCollection.Configure<Fdc3Options>(fdc3Configuration);
57+
serviceCollection.Configure<Fdc3Options>(configuration);
6258
serviceCollection.AddFdc3DesktopAgent(builderAction);
6359
}
6460

src/fdc3/dotnet/DesktopAgent/src/DesktopAgent/Fdc3DesktopAgent.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class Fdc3DesktopAgent : IHostedService
3434
public Fdc3DesktopAgent(
3535
IOptions<Fdc3Options> options,
3636
IMessageRouter messageRouter,
37-
ILoggerFactory? loggerFactory)
37+
ILoggerFactory? loggerFactory = null)
3838
{
3939
_options = options.Value;
4040
_messageRouter = messageRouter;
@@ -65,16 +65,11 @@ public async Task StartAsync(CancellationToken cancellationToken)
6565
{
6666
await _messageRouter.RegisterServiceAsync(Fdc3Topic.FindChannel, FindChannel);
6767

68-
if (_options.BuilderActions.Count <= 0) return;
68+
if (_options.ChannelId == null) return;
6969

7070
// There are no dependencies among possible actions at the moment.
7171
// Future features may introduce dependencies, in that case this solution needs to change
72-
foreach (var task in _options.BuilderActions.Select(x => x(this)).ToArray())
73-
{
74-
await (task);
75-
}
76-
77-
_options.BuilderActions.Clear();
72+
await AddUserChannel(_options.ChannelId);
7873
}
7974

8075
public async Task StopAsync(CancellationToken cancellationToken)

src/fdc3/dotnet/DesktopAgent/tests/DesktopAgent.Tests/EndToEndTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ public async Task InitializeAsync()
4545
opt.Port = _webSocketUri.Port;
4646
}));
4747
services.AddMessageRouter(mr => mr.UseServer());
48-
services.AddFdc3DesktopAgent(fdc3 => fdc3.WithUserChannel(TestChannel));
48+
services.AddFdc3DesktopAgent(fdc3 => fdc3.Configure(builder =>
49+
{
50+
builder.EnableFdc3 = true; //no impact here
51+
builder.ChannelId = TestChannel; //DesktopAgent will call the `AddUserChannel` method, as this property is set for the `_options` field;
52+
}));
4953
});
5054
_host = builder.Build();
5155
await _host.StartAsync();

src/shell/dotnet/Shell/App.xaml.cs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,14 @@ private void ConfigureServices(HostBuilderContext context, IServiceCollection se
113113
.UseAccessToken(_messageRouterAccessToken));
114114

115115
//This can be replaced by the `InjectFdc3BackendServiceIfEnabledFromConfig` extension method
116-
///*
117-
var fdc3Configuration = context.Configuration
118-
.GetSection(Fdc3Options.Fdc3OptionsName);
119-
120-
var fdc3Options = fdc3Configuration
121-
.Get<Fdc3Options>();
116+
///* services.InjectFdc3BackendServiceIfEnabledFromConfig(fdc3ConfigurationSection);
117+
var fdc3ConfigurationSection = context.Configuration.GetSection(Fdc3Options.Fdc3OptionsName);
118+
var fdc3Options = ConfigurationBinder.Get<Fdc3Options>(fdc3ConfigurationSection);
122119

120+
//TODO: This should be feature toggle, once we have feature toggles - instead of having `EnableFdc3` inside Fdc3Options.
123121
if (fdc3Options != null && fdc3Options.EnableFdc3)
124122
{
125-
services.Configure<Fdc3Options>(fdc3Configuration);
126-
services.AddFdc3DesktopAgent(builder => builder.WithUserChannel(fdc3Options.ChannelId ?? "default"));
123+
services.AddFdc3DesktopAgent(builder => builder.Configure<Fdc3Options>(context.Configuration));
127124
}
128125
//*/
129126

0 commit comments

Comments
 (0)