Application lifetime interface (#5)

Application lifetime hooks for services
Options implementations and resolver
Options manager interface to manage options
This commit is contained in:
2021-06-11 13:34:23 +02:00
committed by GitHub
parent 35c8630d8c
commit f818f4152d
19 changed files with 365 additions and 6 deletions
@@ -0,0 +1,6 @@
namespace WpfExtended.Tests.Configuration
{
public sealed class DummyOptions
{
}
}
+3
View File
@@ -7,6 +7,7 @@ using System.Windows.Extensions;
using System.Windows.Extensions.Http;
using WpfExtended.Test;
using WpfExtended.Tests.Http;
using WpfExtended.Tests.Services;
namespace WpfExtended.Tests
{
@@ -31,6 +32,7 @@ namespace WpfExtended.Tests
var logger = sp.GetService(loggerType).As<ILogger>();
return new HttpMessageLogger(logger, new HttpClientHandler());
}));
serviceManager.RegisterOptionsManager();
}
protected override void ApplicationClosing()
@@ -48,6 +50,7 @@ namespace WpfExtended.Tests
protected override void RegisterServices(IServiceProducer serviceProducer)
{
serviceProducer.RegisterSingleton<IDummyService, DummyService>();
}
}
}
+41
View File
@@ -0,0 +1,41 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using System.Extensions;
using System.Windows.Extensions;
using WpfExtended.Tests.Configuration;
namespace WpfExtended.Tests.Services
{
public sealed class DummyService : IDummyService
{
private readonly ILogger<DummyService> logger;
private readonly IOptions<DummyOptions> dummyOptions;
private readonly IUpdateableOptions<DummyOptions> updateableDummyOptions;
private readonly ILiveOptions<DummyOptions> liveOptions;
private readonly ILiveUpdateableOptions<DummyOptions> liveUpdateableOptions;
public DummyService(
ILogger<DummyService> logger,
IOptions<DummyOptions> options,
IUpdateableOptions<DummyOptions> updateableOptions,
ILiveUpdateableOptions<DummyOptions> liveUpdateableOptions,
ILiveOptions<DummyOptions> liveOptions)
{
this.logger = logger.ThrowIfNull(nameof(logger));
this.dummyOptions = options.ThrowIfNull(nameof(options));
this.updateableDummyOptions = updateableOptions.ThrowIfNull(nameof(updateableOptions));
this.liveOptions = liveOptions.ThrowIfNull(nameof(liveOptions));
this.liveUpdateableOptions = liveUpdateableOptions.ThrowIfNull(nameof(liveUpdateableOptions));
}
public void OnClosing()
{
this.logger.LogInformation($"Closing {nameof(DummyService)}");
}
public void OnStartup()
{
this.logger.LogInformation($"Starting {nameof(DummyService)}");
}
}
}
@@ -0,0 +1,8 @@
using System.Windows.Extensions.Services;
namespace WpfExtended.Tests.Services
{
public interface IDummyService : IApplicationLifetimeService
{
}
}