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;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@@ -12,17 +13,37 @@ namespace ZuneModCore
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A list of all available mods
|
/// A list of all available mods
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly IReadOnlyList<Mod> AvailableMods = new List<Mod>
|
public static readonly IReadOnlyList<Type> AvailableModTypes = new List<Type>
|
||||||
{
|
{
|
||||||
new FeaturesOverrideMod(),
|
typeof(FeaturesOverrideMod),
|
||||||
new VideoSyncMod(),
|
typeof(VideoSyncMod),
|
||||||
new WebservicesMod(),
|
typeof(WebservicesMod),
|
||||||
new BackgroundImageMod(),
|
typeof(BackgroundImageMod),
|
||||||
new MbidLocatorMod(),
|
typeof(MbidLocatorMod),
|
||||||
}.AsReadOnly();
|
}.AsReadOnly();
|
||||||
|
|
||||||
public static string ZuneInstallDir { get; set; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Zune");
|
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 Id { get; }
|
||||||
|
|
||||||
public abstract string Title { get; }
|
public abstract string Title { get; }
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
using System.Windows;
|
using System.Windows;
|
||||||
|
using CommunityToolkit.Mvvm.DependencyInjection;
|
||||||
using Microsoft.AppCenter;
|
using Microsoft.AppCenter;
|
||||||
using Microsoft.AppCenter.Analytics;
|
using Microsoft.AppCenter.Analytics;
|
||||||
using Microsoft.AppCenter.Crashes;
|
using Microsoft.AppCenter.Crashes;
|
||||||
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace ZuneModdingHelper
|
namespace ZuneModdingHelper
|
||||||
{
|
{
|
||||||
@@ -29,6 +31,8 @@ namespace ZuneModdingHelper
|
|||||||
// Disable crash and event analytics when in debug
|
// Disable crash and event analytics when in debug
|
||||||
AppCenter.SetEnabledAsync(false);
|
AppCenter.SetEnabledAsync(false);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
ConfigureServices();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void OpenInBrowser(string url)
|
public static void OpenInBrowser(string url)
|
||||||
@@ -38,5 +42,11 @@ namespace ZuneModdingHelper
|
|||||||
UseShellExecute = true
|
UseShellExecute = true
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ConfigureServices()
|
||||||
|
{
|
||||||
|
ServiceCollection services = new();
|
||||||
|
Ioc.Default.ConfigureServices(services.BuildServiceProvider());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user