Giter VIP home page Giter VIP logo

kapsule's People

Contributors

gouline avatar mgouline avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kapsule's Issues

Limitation in transitive dependencies or bug?

Hello,
It seems I found a bug or a limitation on transitive dependencies between 2 modules:

class Deps(
        a: DependenciesA,
        b: DependenciesB
) : DependenciesA by a, DependenciesB by b, HasModules {
    override val modules = setOf(a, b)
}

interface DependenciesA {
    val foo: String
    val foobar: String
}

class ModuleA : DependenciesA, Injects<Deps> {
    override val foo: String = "foo"
    override val foobar: String by required { foo + bar }
}

interface DependenciesB {
    val bar: String
}

class ModuleB : DependenciesB, Injects<Deps> {
    override val bar: String by required { if (foo == "foo") "bar" else "i dont know" }
}

val deps = Deps(ModuleA(), ModuleB()).transitive()

The dependency flow is: a.foobar -> b.bar -> a.foo
Result: When injecting Deps.a.foobar, it throws a NPE because b.bar is null.

I didn't dig into Kapsule, but I think it makes sense because when ModuleA is built, all dependencies are resolved directly, with a dependency on ModuleB which has itself a dependency on ModuleA.

An easy fix would be to split dependencies into 3 modules, in order to not have a "cyclic dependency on Module level". However it would be nice to support this, because this is fine on dependency level.

What do you think?
Thanks.

Possible leak in CallerMap?

Hi!

Really great stuff here, love how simple it is to use and how concise the code base is compared to other dependency injection libraries out there.

However, looking through your code, I noticed you’re extending WeakHashMap to allow for a simple caching mechanism of the last value stored, and I couldn’t help myself but wondering if keeping this reference outside of the “actual” map implementation could result in a leak somehow.
Imagine the following:

class HomeModule(private val activity: HomeActivity) {
  // EDITED: Typo had this return a HomeModule before ...
  val model by lazy { HomeModel(activity) }
}

Now, in our activity:

class HomeActivity : Activity, Injects<HomeModule> {
  private val model by required { model }
}

So far so good. However, when we move away from the HomeActivity, and given that we don’t do any injection in our next activity, then there will be a hard reference to the HomeModule, and therefore also the HomeActivity, which won’t get collected by the garbage collector.

I suppose it's only a valid issue for the last stored key/value pair, seeing as you're extending WeakHashMap.I suspect that's also why you did just that.

Now, if you already thought about this for the last key/value pair as well and have a solution already in your codebase, then please correct me. :smile:

Transitive dependencies

With your solution, how would you manage the dependencies between modules?

For example, ModuleA exposes a retrofit (Retrofit.Builder().[…].build()) and ModuleB exposes the API by using this retrofit object (retrofit.create(MyApi::class.java)).

Should ModuleB implements Injects<ModuleA> or will you give someway ModuleA a reference to ModuleB?

I’ve checked the samples on GitHub but I can’t see the proper way to manage this.

Source: https://medium.com/@lcor1979/very-nice-solution-c4410253e712 (@lcor1979)

Exception using injected property to initialize other properties

Here is a simple example with an injected property where I want to use the injected property to define another property:

class TestModule
{
    val bar = "bar"
}

class Test(module: TestModule): Injects<TestModule>
{
    init { inject(module) }
    val foo by required { bar }
    val foobar = "testing " + foo
}

fun main(args: Array<String>) { println(Test(TestModule()).foobar) }

Running this gives an exception:

Exception in thread "main" kotlin.KotlinNullPointerException
	at space.traversal.kapsule.Delegate$Required.getValue(Delegate.kt:44)
	at com.nobleworks_software.gmail_handler.Test.getFoo
	at com.nobleworks_software.gmail_handler.Test.<init>

i have verified that the call to inject happens before the foobar expression is evaluated and that the lambda passed to required is never invoked.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.