diff --git a/ZuneModCore/Mod.cs b/ZuneModCore/Mod.cs index f7692b4..dcb33a9 100644 --- a/ZuneModCore/Mod.cs +++ b/ZuneModCore/Mod.cs @@ -1,4 +1,5 @@ -using OwlCore.AbstractUI.Models; +using Microsoft.Extensions.DependencyInjection; +using OwlCore.AbstractUI.Models; using System; using System.Collections.Generic; using System.IO; @@ -12,17 +13,37 @@ namespace ZuneModCore /// /// A list of all available mods /// - public static readonly IReadOnlyList AvailableMods = new List + public static readonly IReadOnlyList AvailableModTypes = new List { - new FeaturesOverrideMod(), - new VideoSyncMod(), - new WebservicesMod(), - new BackgroundImageMod(), - new MbidLocatorMod(), + typeof(FeaturesOverrideMod), + typeof(VideoSyncMod), + typeof(WebservicesMod), + typeof(BackgroundImageMod), + typeof(MbidLocatorMod), }.AsReadOnly(); public static string ZuneInstallDir { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Zune"); + private static List? _mods; + public static IReadOnlyList AvailableMods + { + get + { + if (_mods is null) + { + _mods = new(AvailableModTypes.Count); + var services = CommunityToolkit.Mvvm.DependencyInjection.Ioc.Default; + foreach (var modType in AvailableModTypes) + { + var instance = ActivatorUtilities.CreateInstance(services, modType); + if (instance is Mod mod) + _mods.Add(mod); + } + } + return _mods; + } + } + public abstract string Id { get; } public abstract string Title { get; } diff --git a/ZuneModdingHelper/App.xaml.cs b/ZuneModdingHelper/App.xaml.cs index 74feb34..cb62e11 100644 --- a/ZuneModdingHelper/App.xaml.cs +++ b/ZuneModdingHelper/App.xaml.cs @@ -1,7 +1,9 @@ using System.Windows; +using CommunityToolkit.Mvvm.DependencyInjection; using Microsoft.AppCenter; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; +using Microsoft.Extensions.DependencyInjection; namespace ZuneModdingHelper { @@ -29,6 +31,8 @@ namespace ZuneModdingHelper // Disable crash and event analytics when in debug AppCenter.SetEnabledAsync(false); #endif + + ConfigureServices(); } public static void OpenInBrowser(string url) @@ -38,5 +42,11 @@ namespace ZuneModdingHelper UseShellExecute = true }); } + + private static void ConfigureServices() + { + ServiceCollection services = new(); + Ioc.Default.ConfigureServices(services.BuildServiceProvider()); + } } }