WutheringWaves/GameServer/Controllers/Manager/ControllerManager.cs

33 lines
994 B
C#
Raw Normal View History

2024-02-09 22:15:05 +00:00
using GameServer.Controllers.Event;
using GameServer.Controllers.Factory;
using GameServer.Network;
using Microsoft.Extensions.DependencyInjection;
namespace GameServer.Controllers.Manager;
internal class ControllerManager
{
private readonly IServiceProvider _serviceProvider;
private readonly EventHandlerFactory _eventHandlerFactory;
public ControllerManager(IServiceProvider serviceProvider, EventHandlerFactory handlerFactory)
{
_serviceProvider = serviceProvider;
_eventHandlerFactory = handlerFactory;
}
public async Task OnEvent(GameEventType eventType)
{
IEnumerable<GameEventHandler> handlers = _eventHandlerFactory.GetEventHandlers(eventType);
foreach (GameEventHandler handler in handlers)
{
await handler(_serviceProvider);
}
}
public TController Get<TController>() where TController : Controller
{
return _serviceProvider.GetRequiredService<TController>();
}
}