HostBuilder refactor
This commit is contained in:
@@ -32,8 +32,7 @@ namespace LoporritSync;
|
|||||||
|
|
||||||
public sealed class Plugin : IDalamudPlugin
|
public sealed class Plugin : IDalamudPlugin
|
||||||
{
|
{
|
||||||
private readonly CancellationTokenSource _pluginCts = new();
|
private readonly IHost _host;
|
||||||
private readonly Task _hostBuilderRunTask;
|
|
||||||
|
|
||||||
public static Plugin Self;
|
public static Plugin Self;
|
||||||
public Action<IFramework> _realOnFrameworkUpdate = null;
|
public Action<IFramework> _realOnFrameworkUpdate = null;
|
||||||
@@ -51,7 +50,7 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
INotificationManager notificationManager, ITextureProvider textureProvider, IContextMenu contextMenu, IGameInteropProvider gameInteropProvider)
|
INotificationManager notificationManager, ITextureProvider textureProvider, IContextMenu contextMenu, IGameInteropProvider gameInteropProvider)
|
||||||
{
|
{
|
||||||
Plugin.Self = this;
|
Plugin.Self = this;
|
||||||
_hostBuilderRunTask = new HostBuilder()
|
_host = new HostBuilder()
|
||||||
.UseContentRoot(pluginInterface.ConfigDirectory.FullName)
|
.UseContentRoot(pluginInterface.ConfigDirectory.FullName)
|
||||||
.ConfigureLogging(lb =>
|
.ConfigureLogging(lb =>
|
||||||
{
|
{
|
||||||
@@ -172,14 +171,14 @@ public sealed class Plugin : IDalamudPlugin
|
|||||||
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
|
collection.AddHostedService(p => p.GetRequiredService<MarePlugin>());
|
||||||
collection.AddHostedService(p => p.GetRequiredService<EventAggregator>());
|
collection.AddHostedService(p => p.GetRequiredService<EventAggregator>());
|
||||||
})
|
})
|
||||||
.Build()
|
.Build();
|
||||||
.RunAsync(_pluginCts.Token);
|
|
||||||
|
_ = _host.StartAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_pluginCts.Cancel();
|
_host.StopAsync().GetAwaiter().GetResult();
|
||||||
_pluginCts.Dispose();
|
_host.Dispose();
|
||||||
_hostBuilderRunTask.Wait();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user