Ensures that ILuaCsHook will resolve to the existing event service instance.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user