Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/Application/DependencyInjection/ModServiceConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace MDIP.Application.DependencyInjection;
public static class ModServiceConfigurator
{
private static readonly HashSet<Type> _staticInjectionTargets = [];
private static bool _isGameScopeActive;
public static SimpleServiceProvider Provider { get; private set; }
public static IServiceScope CurrentScope { get; private set; }

Expand Down Expand Up @@ -58,8 +59,14 @@ public static void Build()

public static void CreateGameScope()
{
// Prevent duplicate scope creation in the same game session
// This can happen if another mod's prefix patch returns false and manually calls the original method
if (_isGameScopeActive)
return;

DisposeCurrentScope();
CurrentScope = Provider.CreateScope();
_isGameScopeActive = true;
Provider.RefreshSingletonPropertyInjections();
RefreshStaticInjections();
}
Expand All @@ -68,6 +75,7 @@ public static void DisposeCurrentScope()
{
CurrentScope?.Dispose();
CurrentScope = null;
_isGameScopeActive = false;

if (Provider == null)
return;
Expand Down