I'm currently a Staff L6 Android (and part time iOS) Engineer @ Square.
Check out my website, Threads, and Instagram!
๐ก๏ธ A small but powerful & opinionated DI library. Written in Kotlin, and powered by annotation processing.
Home Page: https://af.codes
License: Apache License 2.0
I'm currently a Staff L6 Android (and part time iOS) Engineer @ Square.
Check out my website, Threads, and Instagram!
Instead of:
@Component
interface Parent
@Component(parent = Parent::class)
interface Child
It's more maintainable and searchable to have:
@Component(
children = [Child::class]
)
interface Parent
@Component
interface Child
Injecting the internal Provider<>
interface for a given type should be supported like it is for Dagger.
Below, SomeClass<String, Boolean>
includes OneImpl
in its @Provides
method. OneImpl
injects SomeClass<String, Boolean>
into its constructor.
@Module
interface MyModule1 {
@Binds fun one(one: OneImpl): One
@Binds fun two(two: TwoImpl): Two
}
@Module
abstract class MyModule2 {
@Provides fun one(one: OneImpl): SomeClass<String, Boolean> = SomeClass("test", true)
@Provides fun two(two: TwoImpl): SomeClass<Int, Long> = SomeClass(6, 10L)
}
interface One {
fun doSomething()
}
class OneImpl(
private val two: Two,
private val idk: SomeClass<String, Boolean>
) : One {
override fun doSomething() = two.doSomething()
}
Still exploring if this is what I'd want the experience to be.
This is an issue to request for direct constructor injection.
Currently the @Inject functionality cannot be used on the constructor of a class.
Current behaviour:
data class DependencyA
data class MyClass constructors (
val dependencyA: DependencyA
)
@Module
abstract class DependencyProvider {
@Provides
fun provideMyClass(dependencyA: DependencyA) = MyClass(dependencyA)
}
Expected behaviour:
data class MyClass @Inject constructor (
dependencyA: DependencyA
)
Verify that all dependencies are satisfied at compile time
A simple case:
@Module
abstract class MyModule1 {
@Provides @IntoSet
fun stringOne(): String = "hello"
}
@Module
abstract class MyModule2 {
@Provides @IntoSet
fun stringTwo(): String = "world!"
}
...
@Inject lateinit var strings: Set<String> // ["hello", "world!"]
A qualified case:
@Module
abstract class MyModule1 {
@Provides @IntoSet @HelloWorld
fun stringOne(): String = "hello"
}
@Module
abstract class MyModule2 {
@Provides @IntoSet @HelloWorld
fun stringTwo(): String = "world!"
}
...
@Inject @HelloWorld lateinit var strings: Set<String>
@Inject @HelloWorld lateinit var providedStrings: Set<Provider<String>>
@Inject @HelloWorld lateinit var providedStrings: Provider<Set<String>>
@Inject @HelloWorld lateinit var providedStrings: Provider<Set<Provider<String>>>
When view model types are injected, they should be associated with a view model factory for the injector.
Make the processor incremental.
I have seen that currently, Google provides us with the dynamic feature module to separate features in separate modules. Will this library support multi-module dependency injection?
Circular dependency detection is needed, with build-time error messaging.
interface One
class OneImpl(val two: Two) : One
interface Two
class TwoImpl(val one: One) : Two
When we get One
, we have to get Two
. When we get Two
, we have to get One
. This creates a paradoxical loop.
One -> Two -> One -> Two -> ...
@Binds
@Module
interface SomeModule {
@Binds fun bindOne(impl: OneImpl): One
@Binds fun bindTwo(impl: TwoImpl): Two
}
ModuleBuilder
should detect this by looking at the constructors of OneImpl
and TwoImpl
, comparing parameter types recursively.
@Provides
@Module
abstract class SomeModule {
@Provides fun provideOne(two: Two): One = OneImpl(two)
@Provides fun provideTwo(one: One): Two = TwoImpl(one)
}
ModuleBuilder
should detect this by simply looking at the parameters of each provide method and comparing recursively.
Comparing recursively above can be important for situations like this:
interface One
class OneImpl(val two: Two) : One
interface Two
class TwoImpl(val three: Three) : Two
interface Three
class ThreeImpl(val one: One) : Two
One -> Two -> Three -> One -> Two -> Three -> ...
Is there anything stopping this library from supporting native targets? It would be cool to have true dependency injection support on native. Currently, the only di library for native targets is Kodein and that is service lookup library and not true di.
A simple case:
@Module
abstract class MyModule1 {
@Provides @IntoMap("one")
fun stringOne(): String = "hello, "
}
@Module
abstract class MyModule2 {
@Provides @IntoMap("two")
fun stringTwo(): String = "world!"
}
...
@Inject lateinit var strings: Map<String, String> // ["one": "hello, ", "two": "world!"]
A qualified case:
@Module
abstract class MyModule1 {
@Provides @IntoMap("test", "one")
fun stringOne(): String = "hello, "
}
@Module
abstract class MyModule2 {
@Provides @IntoMap("test", "two")
fun stringTwo(): String = "world!"
}
...
@Inject("test") lateinit var strings: Map<String, String> // ["one": "hello, ", "two": "world!"]
Take this module:
@Module
abstract class Module {
@Provides fun someClass1(): SomeClass<String, Boolean>
@Provides fun someClass2(): SomeClass<Int, Long>
}
The generated code should be able to differentiate between these two return types and inject them correctly.
Android logic, like lifecycles and view models, should not be in the core/processor modules. The processor should be able to find plugins by an annotation and pull out logic.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.