Added ServiceProvider to ApplicationContext and added static callable reference to the ApplicationContext instance
This commit is contained in:
@@ -9,6 +9,22 @@ public class ApplicationContext
|
||||
protected readonly Dictionary<ContextVariableType, LinkedList<ContextVariable>> variables = new();
|
||||
private readonly Lock _lockObject = new();
|
||||
|
||||
private static ApplicationContext? _applicationContext;
|
||||
|
||||
/// <summary>
|
||||
/// When ApplicationContext gets created by the DI container we store the singleton reference so we can provide it
|
||||
/// statically for harmony patches!
|
||||
/// </summary>
|
||||
public ApplicationContext()
|
||||
{
|
||||
_applicationContext = this;
|
||||
}
|
||||
|
||||
public static ApplicationContext? GetInstance()
|
||||
{
|
||||
return _applicationContext;
|
||||
}
|
||||
|
||||
public ContextVariable? GetLatestValue(ContextVariableType type)
|
||||
{
|
||||
lock (_lockObject)
|
||||
|
||||
@@ -19,5 +19,6 @@ public enum ContextVariableType
|
||||
TRANSIT_INFO = 5,
|
||||
APP_BUILDER = 6,
|
||||
LOADED_MOD_ASSEMBLIES = 7,
|
||||
WEB_APPLICATION = 8
|
||||
WEB_APPLICATION = 8,
|
||||
SERVICE_PROVIDER = 9
|
||||
}
|
||||
|
||||
@@ -45,6 +45,9 @@ public static class Program
|
||||
// Initialize Watermak
|
||||
watermark?.Initialize();
|
||||
|
||||
var appContext = serviceProvider.GetService<ApplicationContext>();
|
||||
appContext?.AddValue(ContextVariableType.SERVICE_PROVIDER, serviceProvider);
|
||||
|
||||
// Initialize PreSptMods
|
||||
var preSptLoadMods = serviceProvider.GetServices<IPreSptLoadMod>();
|
||||
foreach (var preSptLoadMod in preSptLoadMods)
|
||||
@@ -52,7 +55,6 @@ public static class Program
|
||||
preSptLoadMod.PreSptLoad();
|
||||
}
|
||||
|
||||
var appContext = serviceProvider.GetService<ApplicationContext>();
|
||||
// Add the Loaded Mod Assemblies for later
|
||||
appContext?.AddValue(ContextVariableType.LOADED_MOD_ASSEMBLIES, mods);
|
||||
// This is the builder that will get use by the HttpServer to start up the web application
|
||||
|
||||
Reference in New Issue
Block a user