mirror of
https://github.com/AlexMacocian/WpfExtended.git
synced 2026-07-15 14:59:30 +00:00
Application lifetime interface (#5)
Application lifetime hooks for services Options implementations and resolver Options manager interface to manage options
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
namespace WpfExtended.Tests.Configuration
|
||||
{
|
||||
public sealed class DummyOptions
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user