Final version
This commit is contained in:
21
TimetableDesigner.Backend.Events/BuilderExtensions.cs
Normal file
21
TimetableDesigner.Backend.Events/BuilderExtensions.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace TimetableDesigner.Backend.Events;
|
||||
|
||||
public static class BuilderExtensions
|
||||
{
|
||||
public static IServiceCollection AddEventQueue<T>(this IServiceCollection services, Action<T> configuration) where T : EventQueue, new()
|
||||
{
|
||||
T builder = new T();
|
||||
configuration(builder);
|
||||
builder.Setup(services);
|
||||
return services;
|
||||
}
|
||||
|
||||
public static void AddEventHandler<T>(this WebApplication app, Func<T, Task> handler) where T : class
|
||||
{
|
||||
IEventQueueSubscriber subscriber = app.Services.GetService<IEventQueueSubscriber>()!;
|
||||
subscriber.Subscribe(handler);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
namespace TimetableDesigner.Backend.Events;
|
||||
|
||||
public class Class1
|
||||
{
|
||||
}
|
||||
8
TimetableDesigner.Backend.Events/EventQueue.cs
Normal file
8
TimetableDesigner.Backend.Events/EventQueue.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace TimetableDesigner.Backend.Events;
|
||||
|
||||
public abstract class EventQueue
|
||||
{
|
||||
internal abstract void Setup(IServiceCollection services);
|
||||
}
|
||||
6
TimetableDesigner.Backend.Events/IEventQueuePublisher.cs
Normal file
6
TimetableDesigner.Backend.Events/IEventQueuePublisher.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace TimetableDesigner.Backend.Events;
|
||||
|
||||
public interface IEventQueuePublisher
|
||||
{
|
||||
public Task PublishAsync<T>(T data) where T : class;
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
namespace TimetableDesigner.Backend.Events;
|
||||
|
||||
public interface IEventQueueSubscriber
|
||||
{
|
||||
void Subscribe<T>(Func<T, Task> handler) where T : class;
|
||||
}
|
||||
@@ -6,4 +6,15 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.2" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.AspNetCore">
|
||||
<HintPath>C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App\10.0.2\Microsoft.AspNetCore.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
Reference in New Issue
Block a user