Patrice: Dagger is a dependency injection framework like Guice. He's asking
how you create a singleton object in Java webland.

Zak: There are lots of ways of doing this. First of all, you do not want to
try to create some sort of cross-instance object graph; each instance
should instantiate the ObjectGraph at instance start. Any other way lies
madness.

The most "natural" place to do this is in a ServletContextListener you
configure in web.xml. Then put the ObjectGraph in the
ServletContext.get/setAttribute collection. However, you're going to
quickly figure out that all of this feels a little inside-out because
really, things like servlets or JAXRS endpoints or whatnot should be
instantiated by Dagger, not the other way around.

Another option is to simply save the ObjectGraph as a static field
somewhere, instantiated as a singleton statically. This suffers from
testability issues but if you want easy, that's the simplest solution.

FWIW, Dagger has some catching up to do before it's ready to replace Guice
on the server-side. You might want to switch to Guice; it will feel less
like swimming upstream but for the most part the API is pretty similar.

Jeff

On Thu, Jul 2, 2015 at 7:40 AM, Patrice (Cloud Platform Support) <
pvoutsi...@google.com> wrote:

> Hi Zack,
>
> I could see saving data in the datastore (as a blob, possibly), and
> retrieving it when needed from there to be a solution.
>
> If I get it correctly, you want to be able to have a single point of
> access for your object graphs? to me, I'd say the best would be datastore
> as a blob. Maybe your precise use-case doesn't warrant that though, so if
> you could expand, it would be great so we can discuss an answer more
> tailored to your question :)
>
> Cheers!
>
> On Wednesday, July 1, 2015 at 4:58:25 PM UTC-4, Zak Taccardi wrote:
>>
>> I am using dagger for dependency injection, and I don't want to create a
>> new object graph for every endpoint.
>>
>> Android lets us extend `Application`, which is a great place to store our
>> singletons so they can be easily reused throughout different pages
>> (actiivities) in the app.
>>
>> What is Google App-Engine's equivalent of this?
>>
>>
>> note: I am okay with this being a per-instance thing.
>>
>  --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to google-appengine+unsubscr...@googlegroups.com.
> To post to this group, send email to google-appengine@googlegroups.com.
> Visit this group at http://groups.google.com/group/google-appengine.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/google-appengine/165b1007-c4f4-4bc1-9069-74c5c2561f2e%40googlegroups.com
> <https://groups.google.com/d/msgid/google-appengine/165b1007-c4f4-4bc1-9069-74c5c2561f2e%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-appengine+unsubscr...@googlegroups.com.
To post to this group, send email to google-appengine@googlegroups.com.
Visit this group at http://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/CADK-0ujDy76NesEKPGis7sAg%2B2HR8K7nj7wqzNRrH%2Bd5%3Dy2-Hw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to