Comments (5)
@alexeysuvorov Thank you for reporting this issue. Unfortunately, injection into library project isn't supported at the moment, which is definitely not good. I'm going to support Android library projects in the nearest future.
from lightsaber.
I am not sure this problem is in library. If all dependencies are defined inside library - everything just fine, but when I want a dependency to be defined out of library - on level of application which host the library - it stops to compile. The more I think about this problem the more I understand that it is quite hard to resolve this on compile time. However I still think it is quite often case and probably it is good to have option to "Promise" some dependencies inside a library module and then provide it by application injector or etc.
I've tried to imagine how could it be:
//------------------------------------------------------------------------------------
//In android library
//------------------------------------------------------------------------------------
@Module
@ProxyModule
class LibraryModule(val hostInjector: Injector) {
@Provides
fun proxyComponent() : IComponent = hostInjector.getInstance<IComponent>()
}
@Component
class LibraryComponent() {
@Provides
@Proxy
fun getLibraryModule(hostInjector: Injector) : LibraryModule(hostInjector)
}
class SomeFragmentInLibrary : Fragment {
override fun onCreate() {
//get
val appInjector = ... //somehow get app injector
val libInjector = Lightsaber.get().createChildInjector(appInjector, LibraryComponent())
//resolve everything we need in lib
}
}
//------------------------------------------------------------------------------------
//In anroid app
//------------------------------------------------------------------------------------
@Module
class ApplicationModule() {
@Provides
fun component() : IComponent = ComponentImpl()
}
@Component
class ApplicationComponent {
@Provides
fun appModule() = ApplicationModule()
}
//We should pass this instance to library
val appInjector = Lightsaber.get().createInjector(ApplicationComponent())
from lightsaber.
Actually you don't need to pass an Injector
to LibraryModule
. Instead you can just use the app injector and inject dependencies into SomeFragmentInLibrary
. I think I've already fixed this issue so an updated version is going to be published soon.
from lightsaber.
@alexeysuvorov Now everything should work fine.
from lightsaber.
Works great in 0.8.3, thank you.
from lightsaber.
Related Issues (8)
- Android performance HOT 3
- Generics limitations HOT 1
- Using Lightsaber to inject dependencies into AAR libraries HOT 4
- Lightsaber and Robolectrics causes java.lang.NoClassDefFoundError HOT 7
- Not Android app and samples crash HOT 3
- Can not locate gradle plugin when building locally HOT 1
- Potential Documentation issues HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from lightsaber.