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

Changed behaviour in Guice 7 #1729

Closed
cdietrich opened this issue May 5, 2023 · 4 comments
Closed

Changed behaviour in Guice 7 #1729

cdietrich opened this issue May 5, 2023 · 4 comments

Comments

@cdietrich
Copy link

cdietrich commented May 5, 2023

the following thing is working in guice up to 6, but is not in 7

public class ADemo {
	
	public static final String CYCLIC_LINKING_DECTECTION_COUNTER_LIMIT = "CYCLIC_LINKING_DECTECTION_COUNTER_LIMIT";
	
	@Named(CYCLIC_LINKING_DECTECTION_COUNTER_LIMIT)
	@Inject(optional=true)
	protected int cyclicLinkingDectectionCounterLimit = 100;
	
	public static void main(String[] args) {
		Injector i = Guice.createInjector(new AbstractModule() {
			@Override
			public void configure() {
				super.configure();
				binder().bindConstant().annotatedWith(Names.named(CYCLIC_LINKING_DECTECTION_COUNTER_LIMIT)).to(0);
			}
		});
		ADemo demo = i.getInstance(ADemo.class);
		System.out.println(demo.cyclicLinkingDectectionCounterLimit); // should print 0
	}

}

is this an intentional change?

@martin-g
Copy link

martin-g commented May 5, 2023

What imports do you use ?

@cdietrich
Copy link
Author

right. i overlooked a javax named. will test again when i replaced these ones too

@cdietrich
Copy link
Author

using import jakarta.inject.Named; indeed helps

@lobaorn
Copy link

lobaorn commented Jun 1, 2024

Hey @cdietrich , 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