如何从其他范围创建对象 [英] how to create an object from a different scope

查看:61
本文介绍了如何从其他范围创建对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Guice中有一个范围为单例的对象。在方法 f()中,我想创建一个新对象,但让Guice进行注入。
我认为绕过注入器不是一个好习惯。

那么如何获得对象的新 Guicy实例?

I have an object in Guice with scope singleton. In method f() I want to create a new object but let Guice do the injection. I think it is not a good practice to pass the injector around.
So how can I get a new "Guicy" instance of object?

推荐答案

如上所述,可能是provider是这样做的方法。在此问题中也提到过。

As suggested above, probably provider is the way to do it. it is also mentioned in this question.

这篇关于如何从其他范围创建对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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