using System; using System.Diagnostics.CodeAnalysis; using Dalamud.Extensions.MicrosoftLogging; using Dalamud.Game; using Dalamud.Game.ClientState.Objects; using Dalamud.Interface.Windowing; using Dalamud.Plugin; using Dalamud.Plugin.Services; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection.Extensions; using Microsoft.Extensions.Logging; using Questionable.Controller; using Questionable.Controller.Steps; using Questionable.Controller.Steps.BaseFactory; using Questionable.Controller.Steps.BaseTasks; using Questionable.Controller.Steps.InteractionFactory; using Questionable.Data; using Questionable.External; using Questionable.Windows; namespace Questionable; [SuppressMessage("ReSharper", "UnusedType.Global")] public sealed class QuestionablePlugin : IDalamudPlugin { private readonly ServiceProvider? _serviceProvider; public QuestionablePlugin(DalamudPluginInterface pluginInterface, IClientState clientState, ITargetManager targetManager, IFramework framework, IGameGui gameGui, IDataManager dataManager, ISigScanner sigScanner, IObjectTable objectTable, IPluginLog pluginLog, ICondition condition, IChatGui chatGui, ICommandManager commandManager, IAddonLifecycle addonLifecycle, IKeyState keyState) { ArgumentNullException.ThrowIfNull(pluginInterface); ServiceCollection serviceCollection = new(); serviceCollection.AddLogging(builder => builder.SetMinimumLevel(LogLevel.Trace) .ClearProviders() .AddDalamudLogger(pluginLog, t => t[(t.LastIndexOf('.') + 1)..])); serviceCollection.AddSingleton(this); serviceCollection.AddSingleton(pluginInterface); serviceCollection.AddSingleton(clientState); serviceCollection.AddSingleton(targetManager); serviceCollection.AddSingleton(framework); serviceCollection.AddSingleton(gameGui); serviceCollection.AddSingleton(dataManager); serviceCollection.AddSingleton(sigScanner); serviceCollection.AddSingleton(objectTable); serviceCollection.AddSingleton(pluginLog); serviceCollection.AddSingleton(condition); serviceCollection.AddSingleton(chatGui); serviceCollection.AddSingleton(commandManager); serviceCollection.AddSingleton(addonLifecycle); serviceCollection.AddSingleton(keyState); serviceCollection.AddSingleton(new WindowSystem(nameof(Questionable))); serviceCollection.AddSingleton((Configuration?)pluginInterface.GetPluginConfig() ?? new Configuration()); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); // individual tasks serviceCollection.AddTransient(); serviceCollection.AddTransient(); // tasks with factories serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTransient(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddSingleton(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection.AddTaskWithFactory(); serviceCollection .AddTaskWithFactory(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); serviceCollection.AddSingleton(); _serviceProvider = serviceCollection.BuildServiceProvider(); _serviceProvider.GetRequiredService().Reload(); _serviceProvider.GetRequiredService(); _serviceProvider.GetRequiredService(); } public void Dispose() { _serviceProvider?.Dispose(); } }