Skip to content

[events] Support Prototype Scope #840

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

Merged
merged 8 commits into from
Jun 24, 2025

Conversation

SentryMan
Copy link
Collaborator

@SentryMan SentryMan commented Jun 24, 2025

now will use a supplier using BeanScope to inject observer beans.

Given a class:

@Singleton
public class TestObserverInjection {

  void observe(@ObservesAsync String e, TestObserver observer) {}
}

This will generate

@Generated("io.avaje.inject.generator")
public final class TestObserverInjection$DI  {

  public static void build(Builder builder) {
    if (builder.isBeanAbsent(TestObserverInjection.class)) {
      var bean = new TestObserverInjection();
      builder.register(bean);
      var beanScope = builder.get(BeanScope.class);
      Supplier<TestObserver> observe$observer = () -> beanScope.get(TestObserver.class,"!observer");
      Consumer<String> observe = e -> bean.observe(e, observe$observer.get());
      builder
          .get(ObserverManager.class)
          .<String>registerObserver(
              String.class, new Observer<>(1000, true, observe, ""));
    }
  }
}

now will use a supplier using `BeanScope` to inject observer beans
@SentryMan SentryMan added this to the 11.6 milestone Jun 24, 2025
@SentryMan SentryMan self-assigned this Jun 24, 2025
@SentryMan SentryMan added the enhancement New feature or request label Jun 24, 2025
now will use a supplier using `BeanScope` to inject observer beans
@SentryMan SentryMan force-pushed the observes-proto-inject branch from 9546c7a to f5be0fb Compare June 24, 2025 01:51
@SentryMan SentryMan enabled auto-merge (squash) June 24, 2025 01:52
@SentryMan SentryMan changed the title [events] support prototype scope [events] Support Prototype Scope Jun 24, 2025
@SentryMan SentryMan requested a review from rbygrave June 24, 2025 03:56
@SentryMan SentryMan merged commit b1b9458 into avaje:master Jun 24, 2025
5 checks passed
@SentryMan SentryMan deleted the observes-proto-inject branch June 24, 2025 11:49
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

Successfully merging this pull request may close these issues.

2 participants