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
@@ -20,6 +20,7 @@ using Barotrauma.Networking;
using Barotrauma.Steam; using Barotrauma.Steam;
using FluentResults; using FluentResults;
using ImpromptuInterface; using ImpromptuInterface;
using LightInject;
using Microsoft.Toolkit.Diagnostics; using Microsoft.Toolkit.Diagnostics;
namespace Barotrauma namespace Barotrauma
@@ -181,7 +182,7 @@ namespace Barotrauma
servicesProvider.RegisterServiceType<IStorageService, StorageService>(ServiceLifetime.Transient); servicesProvider.RegisterServiceType<IStorageService, StorageService>(ServiceLifetime.Transient);
servicesProvider.RegisterServiceType<ISafeStorageService, SafeStorageService>(ServiceLifetime.Transient); servicesProvider.RegisterServiceType<ISafeStorageService, SafeStorageService>(ServiceLifetime.Transient);
servicesProvider.RegisterServiceType<IEventService, EventService>(ServiceLifetime.Singleton); 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<IPackageManagementService, PackageManagementService>(ServiceLifetime.Singleton);
servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton); servicesProvider.RegisterServiceType<IPluginManagementService, PluginManagementService>(ServiceLifetime.Singleton);
servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton); servicesProvider.RegisterServiceType<ILuaScriptManagementService, LuaScriptManagementService>(ServiceLifetime.Singleton);
@@ -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() public void Compile()
{ {
try try
@@ -37,7 +37,14 @@ public interface IServicesProvider
/// Args[1]: Implementing type /// Args[1]: Implementing type
/// </summary> /// </summary>
event System.Action<Type, Type> OnServiceRegistered; 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> /// <summary>
/// Runs compilation of registered services. /// Runs compilation of registered services.
/// </summary> /// </summary>