Assisted injection for JSR 330.
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.buildscript Enable snapshot deployment. Jul 3, 2017
assisted-inject-annotations-dagger2 Use java-library plugin and api/impl Aug 15, 2018
assisted-inject-annotations Use java-library plugin and api/impl Aug 15, 2018
assisted-inject-processor-dagger2 Add generated annotation when it is available Oct 16, 2018
assisted-inject-processor Warn when assisted/provided params are not mixed Nov 25, 2018
assisted-inject-sample-android Make sample application IDs match processor packages Oct 15, 2018
gradle Gradle 4.10.2 Oct 13, 2018
inflation-inject-processor Inflation injection only handles classes, not types Oct 16, 2018
inflation-inject-sample Make sample application IDs match processor packages Oct 15, 2018
inflation-inject Rename layout inflater factory Aug 16, 2018
.gitignore Introduce layout inflation injection Aug 15, 2018
.travis.yml Introduce layout inflation injection Aug 15, 2018
CHANGELOG.md Prepare version 0.3.2 Nov 27, 2018
LICENSE.txt Add license file. Jun 12, 2017
README.md Prepare version 0.3.2 Nov 27, 2018
RELEASING.md Prepare version 0.1.0. Jul 3, 2017
build.gradle Turn R8 on for both samples and validate factory merging Oct 15, 2018
gradle.properties Prepare next development version Nov 27, 2018
gradlew Initial import. Jun 12, 2017
gradlew.bat Gradle 4.10.2 Oct 13, 2018
settings.gradle Add Android sample for assisted injection Oct 15, 2018
signing.keystore Add Android sample for assisted injection Oct 15, 2018

README.md

Assisted Injection for JSR 330

Manually injected dependencies for your JSR 330 configuration. More about assisted injections in the Guice wiki.

Usage

class MyPresenter {
  @AssistedInject
  MyPresenter(Long foo, @Assisted String bar) {}
  
  @AssistedInject.Factory
  interface Factory {
    MyPresenter create(String bar);
  }
}

This will generate the following:

public final class MyPresenter_AssistedFactory implements MyPresenter.Factory {
  private final Provider<Long> foo;

  @Inject public MyPresenter_AssistedFactory(Provider<Long> foo) {
    this.foo = foo;
  }

  @Override public MyPresenter create(String bar) {
    return new MyPresenter(foo.get(), bar);
  }
}

Usage with Dagger 2

In order to allow Dagger to use the generated factory, define an assisted dagger module anywhere in the same gradle module:

@AssistedModule
@Module(includes = AssistedInject_PresenterModule.class)
abstract class PresenterModule {}

The library will generate the AssistedInject_PresenterModule for us.

Download

compileOnly 'com.squareup.inject:assisted-inject-annotations:0.3.2'
annotationProcessor 'com.squareup.inject:assisted-inject-processor:0.3.2'

With Dagger 2:

compileOnly 'com.squareup.inject:assisted-inject-annotations-dagger2:0.3.2'
annotationProcessor 'com.squareup.inject:assisted-inject-processor-dagger2:0.3.2'

License

Copyright 2017 Square, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.