Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Availability For JAVA #81

Closed
BismeetSingh opened this issue Mar 14, 2018 · 8 comments
Closed

Availability For JAVA #81

BismeetSingh opened this issue Mar 14, 2018 · 8 comments
Milestone

Comments

@BismeetSingh
Copy link

Can this be ported to java. Seems better than the dagger hanging over my head.

@arnaudgiuliani
Copy link
Member

Hello,

the interest of Koin is in its ease of use. Check the gists where I put Koin for a Java app:

https://gist.github.com/arnaudgiuliani/446e0d8ee79f4bda38b3057b01098f2e

@jablonskipj
Copy link

jablonskipj commented Mar 25, 2018

I have used it in java. But injection was not done by java code. I have implemented base Kotlin class that I extended in java. Kotlin class was doing the injection and I could use it in java code. It looked like this:

class InjectClass {
  val presenter: Presenter by inject()
}

and then I have extended this class by java:

class InjextExtension extends InjectClass {
    public void fun() {
     ///this is how we access our dependency in java
      getPresenter();
   }
}

@fredy-mederos
Copy link
Contributor

Here there are some utility functions to inject koin components and properties in java.
Basically this utility functions remove the reified types and replace them for java class.

Check it out:
https://gist.github.com/fredy-mederos/b74e8c2f2ca2f0f5d5910bcb694cbdbf

@jablonskipj
Copy link

@fredy-mederos looks like a very good solution. Could you also provide a snippet that shows how injection looks on java site?

@fredy-mederos
Copy link
Contributor

Example in java:

MyManager myManager = KoinJavaUtils.get(MyManager.class);

You can use it in attributes and you can also use the function KoinJavaUtils.inject to get a Lazy object.

I wrote those utility functions to migrate from dagger2 some Android java activities that I can't convert to kotlin and it works good!

@arnaudgiuliani
Copy link
Member

Good job @fredy-mederos! Could be a good contribution and blog post about it 👍

@fredy-mederos
Copy link
Contributor

Thanks!
I'll create some test cases and include them all in the koin-core via PR
It is a good idea the blog post thing... I'll prepare a draft ;)

@arnaudgiuliani
Copy link
Member

I close the issue here to continue on PR. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants