Skip to content

Latest commit

 

History

History
66 lines (41 loc) · 1.87 KB

File metadata and controls

66 lines (41 loc) · 1.87 KB

The mediator pattern implementing on Java Spring Boot

A lightweight, annotation‐driven Mediator pattern implementation for Spring Boot that decouples request objects from their handlers and centralizes the dispatch logic.

Features

  • Annotation-based configuration: Enable the mediator with a single annotation.

  • Generic request/response support: Send commands and queries with typed responses.

  • Automatic handler registration: All your RequestHandler beans are discovered and wired up.

  • Spring Boot starter–style integration: Plug into any existing Spring Boot app.

Getting Started

Maven

<dependency>
  <groupId>com.mehmetsolak</groupId>
  <artifactId>spring-boot-mediator</artifactId>
  <version>1.0.0</version>
</dependency>

Gradle

implementation 'com.mehmetsolak:spring-boot-mediator:1.0.0'

Enable the Mediator

Add @EnableMediator to your main Spring Boot application class:

Enable-Mediator

Defining a Command

Create a class that implements your Request<TResponse> interface. For example, a CarCreateCommand that returns a CarResponse:

Car-Command

Implementing a Command Handler

Implement RequestHandler<CommandType, ResponseType> and annotate it as a Spring bean:

Car-Command-Handler

Sending Commands from a Controller

Inject Mediator into your controller and send() your command:

Car-Controller

Result

Result

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests for improvements.

Contact

For questions or suggestions, please open an issue or contact the maintainer.