sizovs / PipelinR

PipelinR is a lightweight command processing pipeline ❍ ⇢ ❍ ⇢ ❍ for your Java awesome app.
https://github.com/sizovs/PipelinR
MIT License
420 stars 59 forks source link

Quarkus question #16

Closed jhswedeveloper closed 3 years ago

jhswedeveloper commented 3 years ago

Hi thanks for an amazing lib.

Question how would one integrate this library with Quarkus stack?

I've tried following setup but only middlewares getting injected and no command handlers :/

@ApplicationScoped
public class TestHandler implements Command.Handler<UserRegisterCmd, UserRegisterCmd.Response> {

    @Override
    public UserRegisterCmd.Response handle(UserRegisterCmd command) {
        return new UserRegisterCmd.Response("");
    }

}
@ApplicationScoped
public class PipelineConfiguration {

    @Inject
    Instance<Command.Handler> handlers;

    @Inject
    Instance<Command.Middleware> middlewares;

    @SuppressWarnings("unchecked")
    @Produces
    public Pipeline pipeline() {
        return new Pipelinr()
                .with(handlers::stream)
                .with(middlewares::stream);
    }

}
jhswedeveloper commented 3 years ago

Ok this seems to work

@Slf4j
@Dependent
public class PipelineConfiguration {

    @Inject
    Instance<Command.Handler<?, ?>> handlers;
    @Inject
    Instance<Command.Middleware> middlewares;

    @SuppressWarnings("unchecked")
    @Produces
    public Pipeline pipeline() {
        var commandHandlers = handlers.stream().map(r -> (Command.Handler) r).collect(toList());
        return new Pipelinr()
                .with(middlewares::stream)
                .with(commandHandlers::stream);
    }

}

I'll close this one