How to use different technologies to achieve a event publish subscriber system
- Delegates
- Events
- Mediator Design Pattern
- Event Bus
- CQRS using MediatR
- Docker Containers
- RabbitMQ
- CQRS with RabbitMQ
- SignalR
- Background Service
- WebRTC
- Data Streaming
- Event Brokers/ Stores Interface like RabbitMQ/ Kafka/ Redis
- install swagger
- install mediatr
- create classes for entities > repositories
- create classes for dto models like
CarResponseModel
andCarRequestModel
- add
using MediatR;
on top of files from here on - create classes for requests like
GetCarsQuery
andCreateCarCommand
, then extendIRequest<TResponse>
whereTResponse
is response object type - create classes for handlers like
GetCarsQueryHandler
andCreateCarCommandHandler
, then extendIRequestHandler<IRequest,TResponse>
- example for the above will be
GetCarsQuery : IRequest<CarResponseModel>
andCreateCarCommandHandler : IRequestHandler<GetCarsQuery,CarResponseModel>
. Note thatCarResponseModel
can beint
,bool
,string
etc - In
Program.cs
addbuilder.Services.AddMediatR(typeof(Program).GetTypeInfo().Assembly);
to reqister MediatR in DI container - In the controler add
private IMediator _mediator;
- write controller action
Query
andCommand
are refered to asRequest
in MediatREvent
is refered to asNotification
in MediatR- A
Request
should be immutable so the setter property removed i.e{ get; }
- Request pipeline: Controller > Query or Command
Tresponse
> HandlerTrequest,Tresponse
> Repository. Here Trequest is the Query/Command type.
dotnet add package MediatR --version 10.0.1
dotnet add package MediatR.Extensions.Microsoft.DependencyInjection --version 10.0.1