Skip to content

Commit 98b3514

Browse files
committed
using event dispatcher pattern on handlers
1 parent 90e8cca commit 98b3514

4 files changed

Lines changed: 11 additions & 62 deletions

File tree

src/Disc.NET/Handlers/HandlerBase.cs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,21 @@
1-
using Disc.NET.Client.SDK.Interfaces;
2-
using Disc.NET.Commands;
1+
using Disc.NET.Client.SDK;
2+
using Disc.NET.Client.SDK.Interfaces;
33
using Disc.NET.Commands.Contexts;
44
using Disc.NET.Shared.Configurations;
5-
using Disc.NET.Shared.Enums;
65
using Disc.NET.Shared.Serializer;
76
using System.Text.Json;
8-
using Disc.NET.Client.SDK;
97

108
namespace Disc.NET.Handlers;
119

1210
internal abstract class HandlerBase<TContext> where TContext : IContext
1311
{
14-
private IHandler? _next;
1512
protected IClient Client;
1613
protected DiscNetSerializer Serializer;
1714
protected HandlerBase(AppConfiguration appConfiguration)
1815
{
1916
Client = ClientSingleton.GetInstance(appConfiguration);
2017
Serializer = DiscNetSerializer.GetInstance();
2118
}
22-
23-
24-
public void SetNext(IHandler? next)
25-
{
26-
_next = next;
27-
}
28-
public virtual async Task HandleAsync(GatewayEvent @event, JsonDocument contextJson, AppConfiguration configuration)
29-
{
30-
if (_next != null)
31-
{
32-
await _next.HandleAsync(@event, contextJson, configuration);
33-
}
34-
}
35-
3619
protected abstract CommandContext BuildCommandContext(JsonDocument contextJson, AppConfiguration appConfiguration);
3720
protected abstract InteractionContext BuildInteractionContext(JsonDocument contextJson, AppConfiguration appConfiguration);
3821

src/Disc.NET/Handlers/HandlerCommandBase.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
using Disc.NET.Commands;
1+
using Autofac;
2+
using Disc.NET.Commands;
23
using Disc.NET.Commands.Contexts;
34
using Disc.NET.Commands.Contexts.Models;
5+
using Disc.NET.Commands.Responses;
6+
using Disc.NET.Configuration;
47
using Disc.NET.Shared.Configurations;
58
using Disc.NET.Shared.Extensions;
69
using System.Reflection;
710
using System.Text.Json;
8-
using Autofac;
9-
using Autofac.Core;
10-
using Disc.NET.Commands.Responses;
11-
using Disc.NET.Configuration;
1211

1312
namespace Disc.NET.Handlers
1413
{

src/Disc.NET/Handlers/HandlerFactory.cs

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/Disc.NET/Handlers/IHandler.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using System.Text.Json;
2-
using Disc.NET.Shared.Configurations;
1+
using Disc.NET.Shared.Configurations;
32
using Disc.NET.Shared.Enums;
3+
using System.Text.Json;
44

55
namespace Disc.NET.Handlers
66
{
77
internal interface IHandler
88
{
9-
Task HandleAsync(GatewayEvent @event, JsonDocument context, AppConfiguration configuration);
10-
void SetNext(IHandler? next);
9+
Task HandleAsync(JsonDocument context, AppConfiguration configuration);
10+
GatewayEvent GetEventType();
11+
1112
}
1213
}

0 commit comments

Comments
 (0)