为什么有两个带有Google Guice依赖项注入框架的单例实例 [英] why there is two instances of a singleton with Google Guice dependency injection framework

查看:83
本文介绍了为什么有两个带有Google Guice依赖项注入框架的单例实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中有两个Singleton实例,都是由Google Guice创建的.

There’s 2 Singleton instances, both created by Google Guice, in my application.

那怎么可能?

绑定操作如下:

bind(Foo.class).to(FooImpl.class).in(Scopes.SINGLETON);

推荐答案

这里的问题是绑定声明.

The problem here was the binding declaration.

我们通过将绑定声明替换为:

We fixed it by replacing the binding declaration to:

bind(FooImpl.class).in(Scopes.SINGLETON);
bind(Foo.class).to(FooImpl.class); 

这篇关于为什么有两个带有Google Guice依赖项注入框架的单例实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆