Retrieving injected items inside a Main class

16 views
Skip to first unread message

Hyun Joon Seol

unread,
Sep 17, 2017, 3:53:45 AM9/17/17
to finatra-users
Hi,
I'm using a c.t.inject.App for my application since it doesn't require any connections in/out.

I have multiple application logics defined in modules. I have no problems retrieving injected values within modules.

Now, in my main class inside run(), I need to actually retrieve those values. I have overridden the `modules` val. But I can't figure out how to get the values that are provided by my @Provides methods.

If I add @Inject() arguments to the class, then the Main object complains with `Unspecified value parameter`. How do I retrieve those values within the main class?

Hyun Joon Seol

unread,
Sep 17, 2017, 4:07:31 AM9/17/17
to finatra-users
I solved my own problem using Injector.instance.
However, the application logics have the same type, and now I get a runtime error saying

A binding to org.apache.kafka.streams.KafkaStreams was already configured at com.ds.foo.modules.TestStream$.provideTestStreamKStreamBuilder() (via modules: com.google.inject.util.Modules$OverrideModule -> com.ds.foo.modules.TestStream$).
at com.ds.foo.modules.TestStream2$.provideTestStreamKStreamBuilder(TestStream2.scala:25) (via modules: com.google.inject.util.Modules$OverrideModule -> com.ds.foo.modules.TestStream2$)

and also, if I have a flag module that is used by the two modules TestStream and TestStream2, how do I give them different values on the command line?

Christopher Coco

unread,
Sep 17, 2017, 6:03:44 PM9/17/17
to Hyun Joon Seol, finatra-users
Hi there,

We've been meaning to add more documentation and examples around c.t.inject.app.App sorry that it is currently lacking.

As you've realized, if you want to access to an instance bound to the object graph, you would use the injector (injector.instance[T]) to do so. 

Your error looks like it's coming because it seems you may have incorrectly bound the same type twice with override modules (I'm hoping this is in a test). Did you perhaps accidentally add the same module twice to the list of override modules?

For your flag question, you can't reuse the same flag in two different ways and try to give it two different values in the same process. Flags represent parsed command line state. Either use two flags or start two processes using the same flag with different values.

Thanks,
-c

--
You received this message because you are subscribed to the Google Groups "finatra-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to finatra-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages