Right, Guice scopes singletons to the Injector. There should
probably be the same functionality with Transfuse's Injector. I
like the idea though of having a single injector for the entire
application. This supports the Singleton scope across the entire
application.
Transfuse, although it targets Android specifically, is not
necessarily Android specific. Transfuse could be adopted to support
other frameworks. In fact, my coworkers and I were talking about
using it behind a Swing application. With that in mind, Singletons
are not tied directly to the Android Application. I decided to take
this route to support JSR330 and from some advice in the Android
documentation. The documentation stated that singletons should be
written using a static final holder variable instead of using the
Application. (nearest thing I could find recently: "
There is normally no need to subclass Application.
In most situation, static singletons can provide the same
functionality in a more modular way."
http://developer.android.com/reference/android/app/Application.html
From my understanding of Android, Applications are just Singletons
in your application. This means that they should be compatible with
the singleton scope I described above. In other words, you don't
risk a memory leak if you hold a reference to them in a singleton.
You should be able to inject an Application into a singleton (which
is a bug I'm trying to fix currently :-) ).
Have you looked at the custom scopes functionality available in
Transfuse? I believe it supports the cases you mentioned. I've
purposefully left it open so you can define scopes around anything
you like, as long as they implement the
org.androidtransfuse.scope.Scope interface. Each scope is a
Singleton in Transfuse, but you can base the backing code on
whatever you like (location, time, credentials, etc). This makes it
extremely flexible.
Yes, @Factory is basically an analogy for Assisted Injection.
Technically you could use it to write providers as well if necessary
(ie: no @Assisted arguments).
For the case you gave:
Each object's scope is defined on the module level. This gives
Transfuse the necessary opportunity to wire up the graph
accordingly.
Im not sure type literals are necessary in Transfuse, because you
can define the generics in a @Provides method:
@Provides
List<String> getStringList()...
Transfuse is smart enough to recognize the entire type, and
qualifier annotations.
And I agree, Transfuse should not mess around with the Classloader.
Transfuse should already be done with its work by the time
classloading happens.
John