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

Annotations @Provides and @Singleton do not work together #1670

Open
groov1kk opened this issue Mar 26, 2023 · 3 comments
Open

Annotations @Provides and @Singleton do not work together #1670

groov1kk opened this issue Mar 26, 2023 · 3 comments

Comments

@groov1kk
Copy link

Hello

Annotations @Provides and @Singleton do not work together if I try to return class type instead of interface:

  @Provides @Singleton
  InMemoryTransactionLog provideTransactionLog() {
    ...
  }

I look through the implementation and noticed, that method findScopeAnnotation(Errors, Class) just checks whether the provided class was marked by @Singleton annotation. The problem is that I can't mark by this annotation third party classes.

@GedMarc
Copy link

GedMarc commented Mar 30, 2023

That it by design,
Singletons must be registered in a binder, as either a plain or eager singleton,
Specifying @provides does not give you this definition that guice provides above other D.Is

Adding provides and registering a bind In a module will make it a lazy singleton, using .asEagerSingleton for the other.....

@GedMarc
Copy link

GedMarc commented Mar 30, 2023

Guice is modular in design, third party libraries either bind manually or use one's that are strictly DI compliant, CDI third party does not match DI

@lobaorn
Copy link

lobaorn commented Jun 1, 2024

Hey @groov1kk @GedMarc , letting you know since you may be targeting Guice 7.0.0, about the new Micronaut Guice project, that depending on your usecase could be a useful replacement: micronaut-projects/micronaut-guice#9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants