Summary of "CQRS And MediatR In ASP.NET Core - Commands, Notifications, Behaviours"
Video Summary
In the video titled "CQRS And MediatR In ASP.NET Core - Commands, Notifications, Behaviours," the speaker continues the discussion on the integration of CQRS (Command Query Responsibility Segregation) and MediatR in ASP.NET Core. The focus is on implementing commands, notifications, and behaviors.
Key Concepts and Features:
-
Commands:
- The speaker demonstrates how to create an
AddProductCommandthat updates a fake data store. - The command is implemented as a record that inherits from the
IRequestinterface, indicating no return value. - A corresponding handler,
AddProductHandler, is created to process the command, utilizing dependency injection for the data store. - The controller uses the
Sendmethod to handle HTTP POST requests, returning a 201 status code and the created product.
- The speaker demonstrates how to create an
-
Notifications:
- Notifications allow handling a single request by multiple handlers, useful for independent operations like sending emails or invalidating caches.
- The speaker modifies the command flow to publish a
ProductAddedNotification, which is handled by two different handlers:EmailHandlerandCacheInvalidationHandler. - The implementation demonstrates that after a product is added, notifications can trigger additional actions without the original command being aware of them.
-
Behaviors:
- Behaviors are introduced as a way to handle cross-cutting concerns such as logging, validation, and authorization.
- A
LoggingBehaviorclass is created, implementing theIPipelineBehaviorinterface, which logs information before and after handling a request. - The behavior is registered in the program class, allowing it to be used generically across different requests and handlers without modifying existing code.
Practical Guides:
- The speaker encourages viewers to practice implementing PUT and DELETE requests based on the provided examples.
- Links to additional resources, including a book on ASP.NET Core Web API, are provided for further learning.
Main Speakers/Sources:
The speaker is not named in the subtitles, but they guide viewers through the practical implementation of CQRS and MediatR concepts in ASP.NET Core.
Category
Technology