Skip to content

lukaville/toothpick-reflect

Repository files navigation

Toothpick Reflect

The toothpick-reflect artifact is an API-compatible implementation of Toothpick 1.x which uses 100% reflection instead of annotation processing for use during development.

Build Status License

Usage

  1. Add jcenter() maven repository:

    repositories {
        ...
        jcenter()
    }
  2. Use reflect-runtime artifact for IDE builds:

    dependencies {
      if (properties.containsKey('android.injected.invoked.from.ide')) {
        implementation 'com.lukaville.toothpick.reflect:toothpick-reflect-runtime:0.1.0'
      } else {
        implementation 'com.github.stephanenicolas.toothpick:toothpick-runtime:1.1.3'
        kapt 'com.github.stephanenicolas.toothpick:toothpick-compiler:1.1.3'
      }
    }

    * replace kapt with annotationProcessor for Java modules

  3. If you are using factory registries and member injector registries you need to instanciate them using reflection:

    • Replace this:

      FactoryRegistryLocator.setRootRegistry(FactoryRegistry());
      MemberInjectorRegistryLocator.setRootRegistry(MemberInjectorRegistry());
    • With this:

      FactoryRegistryLocator.setRootRegistry(Class.forName("mypackage.FactoryRegistry").getConstructor().newInstance());
      MemberInjectorRegistryLocator.setRootRegistry(Class.forName("mypackage.MemberInjectorRegistry").getConstructor().newInstance());

    Also, if you are using obfuscation you need to keep names for the registries so reflective instantiation doesn't fail.

Limitations

  • @ProvidesSingletonInScope annotation is not supported because it's not available at runtime, use providesSingletonInScope() binding instead. It can be fixed in the future by monkey-patching this annoation
  • Superclass member injection is not implemented for dependencies created using factories (see FactoryGenerator.java)
  • This implementation may contain bugs, please do not use for production

About

API-compatible implementation of Toothpick 1.x which uses 100% reflection instead of annotation processing for use during development

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published