Auto binder for Dagger 2

Binding module generator for Dagger 2 Library https://github.com/google/dagger

License

License

Categories

Categories

Auto Application Layer Libs Code Generators
GroupId

GroupId

ru.ztrap.tools
ArtifactId

ArtifactId

auto-binder-core
Last Version

Last Version

1.0.3
Release Date

Release Date

Type

Type

jar
Description

Description

Auto binder for Dagger 2
Binding module generator for Dagger 2 Library https://github.com/google/dagger
Project URL

Project URL

https://github.com/zTrap/Auto-binder
Source Code Management

Source Code Management

https://github.com/zTrap/Auto-binder

Download auto-binder-core

How to add to project

<!-- https://jarcasting.com/artifacts/ru.ztrap.tools/auto-binder-core/ -->
<dependency>
    <groupId>ru.ztrap.tools</groupId>
    <artifactId>auto-binder-core</artifactId>
    <version>1.0.3</version>
</dependency>
// https://jarcasting.com/artifacts/ru.ztrap.tools/auto-binder-core/
implementation 'ru.ztrap.tools:auto-binder-core:1.0.3'
// https://jarcasting.com/artifacts/ru.ztrap.tools/auto-binder-core/
implementation ("ru.ztrap.tools:auto-binder-core:1.0.3")
'ru.ztrap.tools:auto-binder-core:jar:1.0.3'
<dependency org="ru.ztrap.tools" name="auto-binder-core" rev="1.0.3">
  <artifact name="auto-binder-core" type="jar" />
</dependency>
@Grapes(
@Grab(group='ru.ztrap.tools', module='auto-binder-core', version='1.0.3')
)
libraryDependencies += "ru.ztrap.tools" % "auto-binder-core" % "1.0.3"
[ru.ztrap.tools/auto-binder-core "1.0.3"]

Dependencies

runtime (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.60

Project Modules

There are no modules declared in this project.

OBSOLETE. Anvil provides better functionality. Try it out

Automatic binder for Dagger 2

Automatically generated dagger module with @Binds methods

Download

Install

implementation "ru.ztrap.tools:auto-binder-core:1.0.6"
kapt "ru.ztrap.tools:auto-binder-processor:1.0.6"

Usage

Basics

In order to allow compiler generate dagger module and @Binds methods, define an auto-binder dagger module anywhere in the same gradle module with @AutoBindTo classes:

@Module(includes = [AutoBinder_SampleModule::class])
@AutoBinderModule
object SampleModule

Single binding

interface Contract {
    interface IPresenter
}

@AutoBindTo(Contract.IPresenter::class)
class Presenter : Contract.IPresenter

This will generate the following:

@Module
public abstract class AutoBinder_SampleModule {
  private AutoBinder_SampleModule() {
  }

  @Binds
  abstract Contract.IPresenter bindPresenterToContract$IPresenter(Presenter binding);
}

Into set

interface Interceptor {
    fun intercept(pipeline: Pipeline)
}

@AutoBindTo(Interceptor::class, AutoBindTo.Type.INTO_SET)
class FirstInterceptor : Interceptor

@AutoBindTo(Interceptor::class, AutoBindTo.Type.INTO_SET)
class SecondInterceptor : Interceptor

This will generate the following:

@Module
public abstract class AutoBinder_SampleModule {
  private AutoBinder_SampleModule() {
  }

  @Binds
  @IntoSet
  abstract Interceptor bindFirstInterceptorToInterceptor(FirstInterceptor binding);

  @Binds
  @IntoSet
  abstract Interceptor bindSecondInterceptorToInterceptor(SecondInterceptor binding);
}

Into map

Default map keys (representations of dagger.multibindings-keys)

Dagger name Our name
ClassKey AutoClassKey
IntKey AutoIntKey
LongKey AutoLongKey
StringKey AutoStringKey

Example

interface Interceptor {
    fun intercept(pipeline: Pipeline)
}

@AutoStringKey("first")
@AutoBindTo(Interceptor::class, AutoBindTo.Type.INTO_MAP)
class FirstInterceptor : Interceptor

@AutoStringKey("second")
@AutoBindTo(Interceptor::class, AutoBindTo.Type.INTO_MAP)
class SecondInterceptor : Interceptor

This will generate the following:

@Module
public abstract class AutoBinder_SampleModule {
  private AutoBinder_SampleModule() {
  }

  @Binds
  @IntoMap
  @StringKey("first")
  abstract Interceptor bindFirstInterceptorToInterceptor(FirstInterceptor binding);

  @Binds
  @IntoMap
  @StringKey("second")
  abstract Interceptor bindSecondInterceptorToInterceptor(SecondInterceptor binding);
}

Qualifiers

Annotation marked with dagger.Qualifier annotation will be automatically copied to generated @Binds method only if parameter translateQualifier == true in @AutoBindTo

Example

interface Interceptor {
    fun intercept(pipeline: Pipeline)
}

@Named("first")
@AutoBindTo(Interceptor::class, AutoBindTo.Type.INTO_SET)
class FirstInterceptor : Interceptor

@Named("second")
@AutoBindTo(Interceptor::class, AutoBindTo.Type.INTO_SET)
class SecondInterceptor : Interceptor

This will generate the following:

@Module
public abstract class AutoBinder_SampleModule {
  private AutoBinder_SampleModule() {
  }

  @Binds
  @IntoSet
  @Named("first")
  abstract Interceptor bindFirstInterceptorToInterceptor(FirstInterceptor binding);

  @Binds
  @IntoSet
  @Named("second")
  abstract Interceptor bindSecondInterceptorToInterceptor(SecondInterceptor binding);
}

Developed By

License

Copyright 2019 zTrap.

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.

Versions

Version
1.0.3
1.0.2
1.0.0