mirror of
https://github.com/ZuneDev/ZuneModdingHelper.git
synced 2026-07-27 13:12:21 -07:00
Enable mod constructors to allow dependency injection
This commit is contained in:
+28
-7
@@ -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
|
||||
/// <summary>
|
||||
/// A list of all available mods
|
||||
/// </summary>
|
||||
public static readonly IReadOnlyList<Mod> AvailableMods = new List<Mod>
|
||||
public static readonly IReadOnlyList<Type> AvailableModTypes = new List<Type>
|
||||
{
|
||||
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<Mod>? _mods;
|
||||
public static IReadOnlyList<Mod> 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; }
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user