diff --git a/Libraries/SPTarkov.Server.Core/DI/ServiceLocator.cs b/Libraries/SPTarkov.Server.Core/DI/ServiceLocator.cs new file mode 100644 index 00000000..e30392c4 --- /dev/null +++ b/Libraries/SPTarkov.Server.Core/DI/ServiceLocator.cs @@ -0,0 +1,22 @@ +namespace SPTarkov.Server.Core.DI +{ + /// + /// A service locator designed specifically for Harmony patches and other + /// parts of the application that do not have direct access to the Dependency Injection (DI) system. + /// + /// This should not be used at all when having direct access to DI. + /// + public static class ServiceLocator + { + public static IServiceProvider ServiceProvider + { + get; + private set; + } + + internal static void SetServiceProvider(IServiceProvider provider) + { + ServiceProvider = provider; + } + } +} diff --git a/Libraries/SPTarkov.Server.Core/Utils/App.cs b/Libraries/SPTarkov.Server.Core/Utils/App.cs index 89106664..b7c22e3f 100644 --- a/Libraries/SPTarkov.Server.Core/Utils/App.cs +++ b/Libraries/SPTarkov.Server.Core/Utils/App.cs @@ -11,6 +11,7 @@ namespace SPTarkov.Server.Core.Utils; [Injectable(InjectionType.Singleton)] public class App( + IServiceProvider _serviceProvider, ISptLogger _logger, TimeUtil _timeUtil, RandomUtil _randomUtil, @@ -30,6 +31,8 @@ public class App( public async Task InitializeAsync() { + ServiceLocator.SetServiceProvider(_serviceProvider); + // execute onLoad callbacks _logger.Info(_localisationService.GetText("executing_startup_callbacks"));