Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI into Pipeline behavior - Mediatr-ts + Inversify #29

Open
turkysha opened this issue Dec 26, 2024 · 2 comments
Open

DI into Pipeline behavior - Mediatr-ts + Inversify #29

turkysha opened this issue Dec 26, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@turkysha
Copy link

Hi,
I want to DI something into my pipeline behavior but I am not able to since pipeline behavior constructor takes "...args: unknown[]" as arguments.

this is what I want to do:

@pipelineBehavior()
class ValidationBehaviour implements PipelineBehavior {
    private validationController: ValidationController;

    constructor(@inject(ValidationController) validationController: ValidationController) {
        this.validationController = validationController;
    }
    
    async handle(request: RequestData<unknown>, next: () => unknown): Promise<unknown> {    
        this.validationController.validate(request);
        return await next();
    }

}
export { ValidationBehaviour }

This is the error I get if I try to setOrder of pipeline behaviors in mediator:

Type 'typeof ValidationBehaviour' is not assignable to type 'PipelineBehaviorClass'.
  Types of construct signatures are incompatible.
    Type 'new (validationController: ValidationController) => ValidationBehaviour' is not assignable to type 'new (...args: unknown[]) => PipelineBehavior'.
      Types of parameters 'validationController' and 'args' are incompatible.
        Type 'unknown' is not assignable to type 'ValidationController'.ts(2322)

I belive this is very possible in c# Mediatr implementation.

@m4ss1m0g
Copy link
Owner

The constructor of pipelineBehaviour accept only ...args: unknown[], you cannot inject into the constructor.

Try with Property Injection

@m4ss1m0g m4ss1m0g added the enhancement New feature or request label Dec 27, 2024
@turkysha
Copy link
Author

@m4ss1m0g it would be great if we could do this. In my opinion it's must have feature because you will definitely need to inject something into pipeline behavior (validation, logger, some other controller, etc.).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants