michaelrocks / lightsaber Goto Github PK
View Code? Open in Web Editor NEWCompile time dependency injection framework for JVM languages. Especially for Kotlin.
License: Apache License 2.0
Compile time dependency injection framework for JVM languages. Especially for Kotlin.
License: Apache License 2.0
Hello, my project contains several libraries with business components inside and application which contains UI and use business components from libraries. I want to use logger as a dependency inside business components, but actual logger implementation is known only within application itself, so I have ILogger
interface and MyLibraryComponentImpl @Inject constructor(logger: ILogger)
. When I try to compile my app I see:
Lightsaber failed
java.lang.IllegalStateException: Key for Dependency(type=xxx.project.ILogger, qualifier=null) not found
at io.michaelrocks.lightsaber.processor.generation.GeneratorAdapterExtensionsKt.getKey(GeneratorAdapterExtensions.kt:124)
at io.michaelrocks.lightsaber.processor.generation.GeneratorAdapterExtensionsKt.getInstance(GeneratorAdapterExtensions.kt:90)
at io.michaelrocks.lightsaber.processor.generation.GeneratorAdapterExtensionsKt.getDependency(GeneratorAdapterExtensions.kt:65)
at io.michaelrocks.lightsaber.processor.generation.ProviderClassGenerator.generateProviderMethodArgument(ProviderClassGenerator.kt:193)
at io.michaelrocks.lightsaber.processor.generation.ProviderClassGenerator.generateProvideMethodArguments(ProviderClassGenerator.kt:187)
at io.michaelrocks.lightsaber.processor.generation.ProviderClassGenerator.generateConstructorInvocation(ProviderClassGenerator.kt:160)
at io.michaelrocks.lightsaber.processor.generation.ProviderClassGenerator.generateGetWithInjectorMethod(ProviderClassGenerator.kt:138)
at io.michaelrocks.lightsaber.processor.generation.ProviderClassGenerator.generate(ProviderClassGenerator.kt:88)
at io.michaelrocks.lightsaber.processor.generation.ProvidersGenerator.generate(ProvidersGenerator.kt:37)
at io.michaelrocks.lightsaber.processor.generation.Generator.generateProviders(Generator.kt:168)
at io.michaelrocks.lightsaber.processor.generation.Generator.generate(Generator.kt:59)
at io.michaelrocks.lightsaber.processor.ClassProcessor.performGeneration(ClassProcessor.kt:102)
at io.michaelrocks.lightsaber.processor.ClassProcessor.processClasses(ClassProcessor.kt:67)
at io.michaelrocks.lightsaber.processor.LightsaberProcessor.process(LightsaberProcessor.kt:32)
at io.michaelrocks.lightsaber.plugin.LightsaberTransform.transform(LightsaberTransform.kt:78)
It looks like Android library cannot have dependencies from app which host it.
Hi,
I recently started migrating a project from Dagger 1 to lightsaber and so far, I'm loving it. Great job!
However, all our unit tests are robolectric based and when I initialize an Injector in our App instance within a unit test, I get a NoClassDefFoundError. Seems like robolectric isn't able to find the generated classes, see the stacktrace below..
java.lang.NoClassDefFoundError: io/michaelrocks/lightsaber/InjectionDispatcher
at io.michaelrocks.lightsaber.Lightsaber$DefaultConfigurator.configureInjector(Lightsaber.java:131)
at io.michaelrocks.lightsaber.Lightsaber.createInjectorInternal(Lightsaber.java:76)
at io.michaelrocks.lightsaber.Lightsaber.createInjector(Lightsaber.java:47)
Any idea about how to make the generated classes available to Robolectric?
A workaround would probably be to copy files around in a gradle task, but I'd have to take care of build variants and stuff, so this doesn't sound like fun..
Hello!
I have a question regarding using Lightsaber to push dependencies into AAR libraries.
My setup is, I have an application, and several libraries it relies on, in one project, the libraries being submodules.
What I'm doing is, I've wrapped a Lightsaber "Injector" instance into a generic interface, that I've pushed down to the libraries, so that they can then call "injector.injectMembers(this)" to init their @Inject annotated fields.
Which is working fine, as long as I'm in one project, and the libraries are submodules. However, if I build the libraries as AAR-s, and pull them into the app like that, so they are not submodules anymore, the whole thing stops working.
I've checked the "InjectionDispatcher" class in the "transformClassesWithLightsaberForDebug" folder, and it simply doesn't call "membersInjectors.put()" on the classes from the libraries. My guess is that it only scans app source, and not the source coming from AAR-s.
I've tried with a completely runtime injector (https://github.com/zsoltherpai/feather) and the same setup works fine there. However I really like the fact that Lightsaber doesn't even compile if there are unsatisfied dependencies, so I'd prefer to stick to your library if possible.
Is there anything else I need to do with my libraries to get them working in AAR form aswell? Or is this a use-case that is not supported?
Thanks for the help in advance!
Hi! I would like to use this library on my Android project. I would like to know if it uses reflection to inject fields and if it has better performance avoiding private fields.
Thanks
Hey. I am attempting to build lightsaber locally as I am curious about the project. However I can not get it to build due to a problem with resolving the lightsaber gradle plugin. The error occurs even when I attempt to build and publish to maven local the grade-plugin module:
A problem occurred configuring project ':core'.
> Could not resolve all artifacts for configuration ':core:classpath'.
> Could not find io.michaelrocks:lightsaber-gradle-plugin:0.10.0-beta.
Searched in the following locations:
- file:/Users/Dean/.m2/repository/io/michaelrocks/lightsaber-gradle-plugin/0.10.0-beta/lightsaber-gradle-plugin-0.10.0-beta.pom
- file:/Users/Dean/.m2/repository/io/michaelrocks/lightsaber-gradle-plugin/0.10.0-beta/lightsaber-gradle-plugin-0.10.0-beta.jar
- https://jcenter.bintray.com/io/michaelrocks/lightsaber-gradle-plugin/0.10.0-beta/lightsaber-gradle-plugin-0.10.0-beta.pom
- https://jcenter.bintray.com/io/michaelrocks/lightsaber-gradle-plugin/0.10.0-beta/lightsaber-gradle-plugin-0.10.0-beta.jar
- https://dl.google.com/dl/android/maven2/io/michaelrocks/lightsaber-gradle-plugin/0.10.0-beta/lightsaber-gradle-plugin-0.10.0-beta.pom
- https://dl.google.com/dl/android/maven2/io/michaelrocks/lightsaber-gradle-plugin/0.10.0-beta/lightsaber-gradle-plugin-0.10.0-beta.jar
Required by:
project :core
It seems there might be a circular dependency.
Hi @MichaelRocks,
thank you for supplying this library. I'm a Kotlin starter and therefore slightly wrestling with getting Lightsaber up and running.
In the documentation I read of @Import
and @Provide
. Both I could not find but in examples @Provides
. With these my code is compiling but not running.
Additionally the 0.12.0-beta dependendy in the classpath does not seem to exist in the repositories yet. On the master branch the correct 0.11.1-beta is listed. Perhaps you could make the master branch the default one to make using your project easier for starters?
I find this library very interesting for our current work in Arrow http://arrow-kt.io/ around resolving type class instances at compile time.
I'd like to ask you about the real limitations in resolving generic expressions:
https://github.com/MichaelRocks/lightsaber#generic-injection
The kind of dependency injection we are looking to solve at compile time looks something like this:
interface Functor<F> {
fun map(fa: HK<F, A>, f: (A) -> B): HK<F, B>
}
object OptionFunctorInstance : Functor<OptionHK> {
override fun map(fa: OptionKind<A>, f: (A) -> B): Option<B> = ...
}
functor<OptionHK>() // Compiles because there is a `Functor<Option>` provided
functor<List>() // Does not compile because there is no `Functor<List>` provided
Can we use lightsaber for something like this?
Thanks again for a great library!
Hello Michael. Android version works just fine, but when I've tried to make a java app it just crash after run. I've checked samples and non android samples crash as well. Console output (for Java):
Before injection
Wookiee: null
Droid: null
Darth Vader: null
Planet: null
Exception in thread "main" java.lang.NoClassDefFoundError: io/michaelrocks/lightsaber/InjectionDispatcher
at io.michaelrocks.lightsaber.Lightsaber$DefaultConfigurator.configureInjector(Lightsaber.java:119)
at io.michaelrocks.lightsaber.Lightsaber.createInjectorInternal(Lightsaber.java:70)
at io.michaelrocks.lightsaber.Lightsaber.createInjector(Lightsaber.java:43)
at io.michaelrocks.lightsaber.sample.LightsaberSample.run(LightsaberSample.java:56)
at io.michaelrocks.lightsaber.sample.LightsaberSample.main(LightsaberSample.java:47)
Caused by: java.lang.ClassNotFoundException: io.michaelrocks.lightsaber.InjectionDispatcher
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
Lightsaber version: 0.8.3-beta (but actually I've tried all 0.8.x)
My java version is:
java 9
Java(TM) SE Runtime Environment (build 9+181)
Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
Any ideas?
Thanks.
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.