Ensures that ILuaCsHook will resolve to the existing event service instance.

This commit is contained in:
MapleWheels
2026-01-28 20:33:32 -05:00
committed by Maplewheels
parent 6619def365
commit 92232d114b
3 changed files with 23 additions and 2 deletions

View File

@@ -20,6 +20,7 @@ using Barotrauma.Networking;
using Barotrauma.Steam;
using FluentResults;
using ImpromptuInterface;
using LightInject;
using Microsoft.Toolkit.Diagnostics;
namespace Barotrauma
@@ -181,7 +182,7 @@ namespace Barotrauma
servicesProvider.RegisterServiceType<IStorageService, StorageService>(ServiceLifetime.Transient);
servicesProvider.RegisterServiceType<ISafeStorageService, SafeStorageService>(ServiceLifetime.Transient);
servicesProvider.RegisterServiceType<IEventService, EventService>(ServiceLifetime.Singleton);
servicesProvider.RegisterServiceType<ILuaCsHook, EventService>(ServiceLifetime.Singleton);
servicesProvider.RegisterServiceResolver<ILuaCsHook>(factory => factory.GetInstance<IEventService>() as ILuaCsHook);
servicesProvider.RegisterServiceType<IPackageManagementService, PackageManagementService>(ServiceLifetime.Singleton);
servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton);
servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton);

View File

@@ -100,6 +100,19 @@ public class ServicesProvider : IServicesProvider
}
}
public void RegisterServiceResolver<TSvcInterface>(Func<ServiceContainer, TSvcInterface> factory) where TSvcInterface : class, IService
{
try
{
_serviceLock.EnterReadLock();
ServiceContainer.Register<TSvcInterface>(f => factory(ServiceContainer));
}
finally
{
_serviceLock.ExitReadLock();
}
}
public void Compile()
{
try

View File

@@ -37,7 +37,14 @@ public interface IServicesProvider
/// Args[1]: Implementing type
/// </summary>
event System.Action<Type, Type> OnServiceRegistered;
/// <summary>
/// Registers a factory for resolving the service type.
/// </summary>
/// <param name="factory"></param>
/// <typeparam name="TSvcInterface"></typeparam>
void RegisterServiceResolver<TSvcInterface>(Func<ServiceContainer, TSvcInterface> factory) where TSvcInterface : class, IService;
/// <summary>
/// Runs compilation of registered services.
/// </summary>