More SZ singleton integration

This commit is contained in:
2026-01-25 19:13:09 -06:00
parent 800b5d9def
commit 6d92e3993b
4 changed files with 40 additions and 25 deletions

View File

@@ -9,6 +9,9 @@ public static class SZ
public static bool IsInitalized { get; private set; } = false;
public static readonly SzParser SzParser = new();
public static readonly SzDataHandler SzDataHandler = new();
public static ISzFileManager LocalFileManager
{
get
@@ -35,6 +38,9 @@ public static class SZ
/// <summary>
/// Initalizes the SZ singleton in SzCore
/// </summary>
/// <param name="fileManager">An ISzFileManager instance.</param>
/// <param name="logger">An ISzLogger instance.</param>
/// /// <exception cref="Exception">Throws if SZ has already been initalized</exception>
public static void Init(ISzFileManager fileManager, ISzLogger logger)
{
if (IsInitalized) throw new Exception("Cannot initalize SZ more than once.");
@@ -52,11 +58,11 @@ public static class SZ
throw new Exception("SZ.Init failed: LocalFileManager was null");
}
IsInitalized = true;
AddService(fileManager, true);
AddService(logger, true);
IsInitalized = true;
logger.Log(" -- SZ CORE INITALIZED -- ");
}
@@ -88,16 +94,16 @@ public static class SZ
{
CheckInitialization();
if (!_services.ContainsKey(typeof(T))) return default(T);
if (!_services.ContainsKey(typeof(T))) return default;
return (T)_services[typeof(T)];
}
public static bool RemoveService(Type type)
public static bool RemoveService<T>()
{
CheckInitialization();
if (_protectedServices.Contains(type)) return false;
return _services.Remove(type);
if (_protectedServices.Contains(typeof(T))) return false;
return _services.Remove(typeof(T));
}
private static void CheckInitialization()