Skip to content

WS: Make web socket DI friendly #3914

Description

@kliushnichenko

It would be nice to have a websocket handler DI-friendly in the same way controllers are, for avaje-inject in particular.

The following example won't work due to avaje module lateinit nature:

{
    install(AvajeInjectModule.of(
                BeanScope.builder()
                        .bean(WebsocketHandler.class, new WebsocketHandler()))
    );
    ws("/ws", require(WebsocketHandler.class));
}

The only way I managed to make it is by moving ws() into a separate lateinit extension that should be initialized after Avaje

Activity

  1. jknack commented on Apr 19, 2026

    @jknack
    Member

    do you want to do it? Should we look for annotated web socket handler and add a new code generator for WS?

  2. kliushnichenko commented on Apr 20, 2026

    @kliushnichenko
    ContributorAuthor

    Something like:

    @Websocket("/ws/{id}")
    public class WsHandler {
    
      @OnConnect
      public String onConnect(Context ctx) {
        return "welcome";
      }
    
      @OnMessage
      public String onMessage(Websocket ws, WebSocketMessage message) {
        return message.value();
      }
    
      @OnClose
      public void onClose(Websocket ws, WebSocketCloseStatus status) {}
    
      @OnError
      public void onError(Websocket ws, Throwable cause) {}
    }
  3. added theissue type on Apr 22, 2026
  4. added this to the 4.5.0 milestone on Apr 22, 2026
  5. jknack commented on Apr 22, 2026

    @jknack
    Member

    done #3917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions