johncarl81 / transfuse

:syringe: Transfuse - A Dependency Injection and Integration framework for Google Android
http://androidtransfuse.org/
Apache License 2.0
220 stars 28 forks source link

Using a factory defined in a library #170

Closed dbachelder closed 9 years ago

dbachelder commented 9 years ago

I have a library "utils" that has many of the fundamentals we use in a couple apps, base fragment, activity and module, and I have recently added a @Factory class that I was going to get at via Factories.get() in those base classes (not within the TF dependency graph).

This fails with an exception:

    java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object org.androidtransfuse.Factories$FactoryBuilder.get()' on a null object reference
            at org.androidtransfuse.Factories.get(Factories.java:66)

So first, what am I not doing correctly? I am running apt with the transfuse processor on both the library and the app. If I move the Factory interface into the app project and go after it in a baseclass in the app project, everything is fine.

Second, the factory should throw an exception like new IllegalArgumentException("unable to find factory of type: " + type + ". Please do blah blah blah and read this link: http://blah.com for possible help"

johncarl81 commented 9 years ago

Ah, if Transfuse doesn't run in your library then you'll need to use the @Install annotation on your module:

@TransfuseModule
@Install(LibraryFactory.class)
class Module{}

This will trigger Transfuse to run on the given class.

johncarl81 commented 9 years ago

And I added a fail fast exception when Transfuse can't find an element in a utility class: 4bd8faae227c2fc7cb062078cbe9217e8a8dbfcc FYI, I also added this to Parceler a while back: https://github.com/johncarl81/parceler/commit/bf4e1c5dba76af357364b53241aac6e150002eb9

johncarl81 commented 9 years ago

And this fix should allow you to use Application in @Factory level providers: 0110fe0f5e669de52c202178e07dd37b2a84835d

dbachelder commented 9 years ago

Working great on both counts