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

[Future Enhancement] Use ScopedValue to add the ability to retrieve the Request Context #102

Open
SentryMan opened this issue Nov 30, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@SentryMan
Copy link
Collaborator

I think it would be cool if we added ScopedValue to Context like this:

public interface Context {

  /** Retrieve the current request context */
  ScopedValue<Context> SV_CONTEXT = ScopedValue.newInstance();

}

In this way, every HTTP request can access the context like

  void main() {
    Jex.create().routing(routing -> routing.get("/", ctx -> processRequest())).start();
  }

  void processRequest() {
    Context ctx = Context.SV_CONTEXT.get();

    // do whatever with the context
  }
@SentryMan SentryMan added the enhancement New feature or request label Nov 30, 2024
@rbygrave
Copy link
Contributor

If we did it, we'd probably have a static method like:

  ScopedValue<Context> SV_CONTEXT = ScopedValue.newInstance();

  static Context get() {
    return SV_CONTEXT.get();
  }

So then its use would be:

  void processRequest() {
    Context ctx = Context.get();

    // do whatever with the context
  }

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