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

It's not possible to inject BeanScope #235

Closed
natros opened this issue Jun 10, 2022 · 3 comments · Fixed by #236
Closed

It's not possible to inject BeanScope #235

natros opened this issue Jun 10, 2022 · 3 comments · Fixed by #236
Assignees
Labels
enhancement New feature or request
Milestone

Comments

@natros
Copy link

natros commented Jun 10, 2022

Micronaut allows to inject BeanContext and ApplicationContext. Guice can inject Injector.

My use case is that I'm trying to convert this code that uses guice to avaje-inject

// quartz job factory
class GuiceJobFactory implements JobFactory {
  private final Injector injector;

  @Inject
  GuiceJobFactory(Injector injector) {
    this.injector = injector;
  }

  @Override
  public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) {
    Class<? extends Job> cls = bundle.getJobDetail().getJobClass();
    return injector.getInstance(cls);
  }
}

Thanks

@rbygrave
Copy link
Contributor

Micronaut allows to inject BeanContext and ApplicationContext. Guice can inject Injector.

Oh wow, I didn't know that. Nice use case - dynamically obtain the job to run - got it.

I'll have a look and see how we can inject BeanScope to get the same effect.

@xabolcs
Copy link

xabolcs commented Jan 18, 2023

Hi @natros , would you mind putting here that job factory snippet again, but now in the aveje-inject form?
Thanks!

@SentryMan
Copy link
Collaborator

SentryMan commented Jan 18, 2023

@Singleton
class AvajeJobFactory implements JobFactory {

  private final BeanScope scope;

  AvajeJobFactory(BeanScope scope) {
    this.scope = scope;
  }

  @Override
  public Job newJob(TriggerFiredBundle bundle, Scheduler scheduler) {
    final Class<? extends Job> cls = bundle.getJobDetail().getJobClass();
    return scope.get(cls);
  }
}

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 a pull request may close this issue.

4 participants