Guice

Is it possible to inject an object with scala-guice?

倾然丶 夕夏残阳落幕 提交于 2019-12-07 08:14:26
I would like to inject the scala.io.Source but I failed to find a working solution. This is what I have so far: class Foo @Inject()(var source:Source) { // ... } And the binding: class DependencyInjection extends AbstractModule with ScalaModule { def configure:Unit = { bind[Source.type].to[Source] // bind[Source] didn't work } } Maybe I can wrap the scala.io.Source calls into a local class but it doesn't sound right. Is there a way to inject objects with scala-guice? Because Source is an abstract class, and there are no public extensions for it (and even if there were, you wouldn't be able to

Releasing ORMLite helper on @Singleton

大城市里の小女人 提交于 2019-12-07 07:23:51
问题 I have a @Singleton class where I've injected an instance of OrmLiteSqliteOpenHelper . Do I actually ever need to call the OpenHelperManager.releaseHelper() ? In case I do, where and how should it be done as the class doesn't extend any Android base class where I could get to the onDestroy ? 回答1: There is an ORMLite example Android project which demonstrates this called HelloAndroidNoBase. I'd check it out. The relevant code section from the main Activity is included below. You'll need to

why there is two instances of a singleton with Google Guice dependency injection framework

会有一股神秘感。 提交于 2019-12-07 07:11:38
问题 I am developper in a compagny using Google Guice as dependency injection framework in a MVC architecture. The system use a Singleton model. We just discover that there's two instances of the model in the project and this is problem. I know that Singleton is never the better way, but I am not the project designer. Google Guice is the only model initializer so that there is not "new". Google Guice sometimes inject the model by fields injection and sometime in the constructor itself. But, the

Play/Scala injecting controller into test

…衆ロ難τιáo~ 提交于 2019-12-07 05:16:53
问题 So according to Play 2.4 documentation (https://playframework.com/documentation/2.4.x/ScalaTestingWithScalaTest#Unit-Testing-Controllers), the controller should be set up as a trait like this trait ExampleController { this: Controller => def index() = Action { Ok("ok") } } object ExampleController extends Controller with ExampleController in order for a test to work like this class ExampleControllerSpec extends PlaySpec with Results { class TestController() extends Controller with

What is the purpose for using an empty interface that extends another in Java?

爷,独闯天下 提交于 2019-12-07 03:20:58
问题 I just begin to maintain a Java MVC project which use Java Guice Framework. In almost the entire code, first developers passed as parameter an empty model interface extending another interface. Here's the first Interface: public interface FooModel extends ModelInterface { } And the other interface: public interface ModelInterface { public void addListener(FooListener fooListener); void setFoo(boolean blop); boolean isFoo(); } That does not make any sense for me. Is there a good reason/pattern

How to override binding in GIN

拟墨画扇 提交于 2019-12-07 03:11:37
问题 I find the answer for Guice Overriding Binding in Guice but don't know how to do the same for GIN in GWT. Thanks in advance! 回答1: As far as I know, it's not supported. To answer your comment: If you're running "pure" JUnit tests (not GWTTestcases) you don't use GIN, you use Guice, and in Guice you can override modules. If you want to reuse GIN modules, then wrap them using GinModuleAdapter . So you can do something like this: static class MyGinModule extends GinModule { ... } static class

Constructor Injection using Guice

守給你的承諾、 提交于 2019-12-07 03:05:48
问题 I have some sample code which is using factories. I'd like to clean up the code by removing the factories and use Guice instead. I attempted to do this but I hit a small roadblock. I am really new to Guice, so I am hoping someone can help me out here. Existing client code (Using factories): public class MailClient { public static void main(String[] args) { MailConfig config = MailConfigFactory.get(); config.setHost("smtp.gmail.com"); Mail mail = MailFactory.get(config); mail.send(); } } My

WebSocket.acceptWithActor and @Inject() in the Actor (Play 2.5)

[亡魂溺海] 提交于 2019-12-06 21:40:52
问题 WebSocket.acceptWithActor instantiates a new Akka actor without making use of Guice. With Play 2.4, using the injector for my actor was still possible by importing play.api.Play.current . Snippet from ReactiveMongo documentation: import scala.concurrent.Future import play.api.Play.current // should be deprecated in favor of DI import play.api.libs.concurrent.Execution.Implicits.defaultContext import play.modules.reactivemongo.ReactiveMongoApi import play.modules.reactivemongo.json.collection

How to pass parameters to guicified TestNG test from Surefire Maven plugin?

只谈情不闲聊 提交于 2019-12-06 20:48:24
I'm using Maven + Surefire + TestNG + Guice (latest stable ones) I have "large" test that requires Guice to run. Basically I'm doing it this way: @Test(groups = "large") @Guice(modules = FooLargeTest.Module.class) public class FooLargeTest { public static class Module extends AbstractModule { public void configure() { bindConstant().annotatedWith(FooPort.class).to(5000); // ... some other test bindings } } @Inject Provider<Foo> fooProvider; @Test public void testFoo() { Foo foo = fooProvider.get() // here injection of port is done // it could not be passed to constructor // ... actual test of

Get All the instance subclass of trait using Google Guice

你离开我真会死。 提交于 2019-12-06 18:47:27
I am trying to get All the instances subclass of trait(interface). This trait have multiple implementation which are provided third party users. Is this possible to get All the instances subclasses without explicit binding because I don't have control, Implementation provided by third party users. ? I already saw the same question in which you need to bind explicitly. Code sample: import javax.inject.Inject import com.google.inject._ import scala.collection.JavaConversions._ object DemoApp extends App { val injector = Guice.createInjector(new AllImplModule) injector.getInstance(classOf[Action]