feat: use activatorutilities to create instance of session

This commit is contained in:
Timothy Schenk 2023-08-10 08:28:05 +02:00
parent 8790b1a3bf
commit 3552134186
3 changed files with 5 additions and 6 deletions

View file

@ -8,7 +8,7 @@ namespace Server;
public abstract class AuthSession : TcpSession
{
private readonly ILogger _logger;
private readonly ILogger<AuthSession> _logger;
private readonly IMediator _mediator;
private static readonly byte[] Key = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5, 6, 7 }
@ -21,7 +21,7 @@ public abstract class AuthSession : TcpSession
private readonly ICryptoTransform _decryptor;
protected AuthSession(TcpServer
server, ILogger logger, IMediator mediator) : base(server)
server, ILogger<AuthSession> logger, IMediator mediator) : base(server)
{
_logger = logger;
_mediator = mediator;

View file

@ -23,9 +23,8 @@ public class WonderkingAuthServer : TcpServer, IHostedService
_loggerFactory = loggerFactory;
}
protected override TcpSession CreateSession() => new WonderkingSession(this,
_serviceProvider.GetService<IMediator>() ?? throw new InvalidOperationException(),
_loggerFactory.CreateLogger(nameof(WonderkingSession)));
protected override TcpSession CreateSession() =>
ActivatorUtilities.CreateInstance<WonderkingSession>(_serviceProvider, this);
protected override void OnStarting()
{

View file

@ -9,7 +9,7 @@ public class WonderkingSession : AuthSession
{
private readonly IMediator _mediator;
public WonderkingSession(TcpServer server, IMediator mediator, ILogger logger) : base(server, logger, mediator)
public WonderkingSession(TcpServer server, IMediator mediator, ILogger<WonderkingSession> logger) : base(server, logger, mediator)
{
_mediator = mediator;
}