# RmediatoR

<div style="text-align: left; padding: 1rem 0;">
<img src="./docs/assets/images/logo-dark.png" width="500" aspect-ration="1/1" style="padding: 0.8rem 0;">
<p align="left">
  <a href="#introduction">Introduction</a> •
  <a href="#demonstration">Demonstration</a> •
  <a href="#how-to-use">How to Use</a> •
  <a href="#how-to-use">Contributing</a> •
  <a href="#how-to-use">License</a>
</p>
</div>

## [Introduction](#introduction)

RmediatoR is a Python package inspired by the MediatR library available on NuGet. It allows developers to implement the mediator design pattern in their applications, promoting a clean separation of concerns by centralizing request/response logic and eliminating direct dependencies between components. This package simplifies the communication between different parts of your application, making your code more maintainable and scalable.

## [Demonstration](#demonstration)

Here's a quick example to demonstrate how RmediatoR works:

1. Define a Request and Handler: Create a request class and a handler class that processes the request.
```py
from rmediator.decorators import request, request_handler

# Define a response
class SomeResponse:
    def __init__(self, message):
        self.message = message

# Define a request
@request(SomeResponse)
class SomeRequest:
    pass

# Define a handler for the request
@request_handler(SomeRequest, SomeResponse)
class SomeRequestHandler:
    def handle(self, request: SomeRequest) -> SomeResponse:
        return SomeResponse("Handled!")
```
2. Initialize the mediator and register the handlers
```py
from rmediator import Mediator

mediator = Mediator()

mediator.register_handler(SomeRequest, SomeRequestHandler())
```
3. Send a Request: Use the mediator to send a request and get a response.
```py
# Create a request instance
request = SomeRequest()

# Send the request through the mediator
response = mediator.send(request)

# Output the response
print(response.message)  # Output: Handled!
```
## [How to Use](#how-to-use)

To start using RmediatoR, follow these steps:
1. Installation: First, install the package using pip (or use other options like poetry).
```bash
pip install rmediator
```
2. Creating Requests and Handlers: Define your request and handler classes as shown in the demonstration above. Each request should inherit from the Request class, and each handler should inherit from the Handler class.

3. Registering Handlers: Register your handlers with the mediator. This tells the mediator which handler to use for each request type.

```py
mediator.register_handler(YourRequestClass, YourHandlerClass)
```
4. Sending Requests: Use the mediator to send requests. The mediator will find the appropriate handler and return the response.

```py
response = mediator.send(your_request_instance)
```

## [License](#license)
RmediatoR is licensed under the MIT License. See the [LICENSE](LICENSE) file for more details.

## [Contributing](#contributing)
Contributions are welcome! Please read the [CONTRIBUTING](CONTRIBUTING.md) guidelines for more information on how to get started.

## [Contact](#contact)
For questions or issues, please open an issue on GitHub or contact me on my channels.