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

[Koin 1.0] - Revamped DSL & new Module API #131

Closed
arnaudgiuliani opened this issue May 16, 2018 · 1 comment
Closed

[Koin 1.0] - Revamped DSL & new Module API #131

arnaudgiuliani opened this issue May 16, 2018 · 1 comment
Labels
Milestone

Comments

@arnaudgiuliani
Copy link
Member

arnaudgiuliani commented May 16, 2018

Hello,

we have revamped our Koin DSL to make it clearer. We can now declare our module like follow:

val myModule = module {
  single { ComponentA() }
  
  module("view"){
     single { ComponentB()}
  }
}

A Koin module (declared now with module function) can have an inner module. This DSL is more neutral and better target the idea of declaring module and inner modules.

The following keywords has been deprecated in favor of new ones:

  • applicationContext -> module
  • context -> module
  • bean -> single

(factory has not been touched. You can still use bean keyword)

A module is declared in a path:

  • module { ... } -> definitions are in /
  • module("app") { ... } -> defintions are in /app
  • module("app.view") { ... } -> defintions are in /app/view

Visibility rule is child module can see parent module. This mean that for module:

val myModule = module("app") {
  single { Repository() }
  
  module("view"){
     single { Presenter(get())}
  }
}

-> Presenter can see Repository.

You can now request a component with the optional module parameter, which indicates the required module path to lookup: by inject(module="...") or get(module="...").

If you don't use the module parameter, you will lookup in all the modules as usual, else you will lookup at given module path.

To request Presenter class, you can either write it get<Presenter>() or get<Presenter>(module="app.view")

The old releaseContext function has been renamed to release. If I want to release the Presenter instance, I can just use the module path: release("app.view")

This feature has been deployed in 1.0.0-alpha-8. You can already check it and give us some feedbacks 👍

@arnaudgiuliani arnaudgiuliani created this issue from a note in Koin Dev Board (In progress) May 16, 2018
@arnaudgiuliani arnaudgiuliani added this to the 1.0.0 milestone May 16, 2018
@arnaudgiuliani arnaudgiuliani self-assigned this May 16, 2018
@arnaudgiuliani arnaudgiuliani changed the title [DSL] Rework Koin DSL - introducing Module API [DSL] Revamped DSL & new Module API May 16, 2018
@arnaudgiuliani arnaudgiuliani moved this from In progress to Wait-For-Feedbacks in Koin Dev Board May 16, 2018
@arnaudgiuliani arnaudgiuliani changed the title [DSL] Revamped DSL & new Module API Revamped DSL & new Module API May 17, 2018
@arnaudgiuliani arnaudgiuliani removed their assignment May 17, 2018
@ghost
Copy link

ghost commented May 22, 2018

Those keyword name changes are great and are now more natural with how other dependency injection libs name things.

@arnaudgiuliani arnaudgiuliani moved this from Pinned to Done in Koin Dev Board May 29, 2018
@arnaudgiuliani arnaudgiuliani changed the title Revamped DSL & new Module API [Koin 1.0] - Revamped DSL & new Module API Jun 8, 2018
arnaudgiuliani pushed a commit that referenced this issue May 15, 2020
Updated documentation as per issue #131 in change log
arnaudgiuliani added a commit that referenced this issue May 28, 2020
* update changelog

* Updated dependency quote marks in setup docs (#735)

* remove build-log dump.txt (#724)

* Corrected `applicationContext` to `module` (#779)

Updated documentation as per issue #131 in change log

* Fix typo in Getting Started with Ktor (#796)

* Koin MP setup docv

* Fix KoinTestRule test exception handling. Fixes gh-803

Co-authored-by: Arnaud Giuliani <giuliani.arnaud@gmail.com>
Co-authored-by: Rajanikant Deshmukh <rajanikant.deshmukh@gmail.com>
Co-authored-by: Alexander Falb <221837+elexx@users.noreply.github.com>
Co-authored-by: Dacre Denny <dacre@mooce.co.nz>
Co-authored-by: Marcus Ramsden <marcus@bitsden.com>
Co-authored-by: Jan Mottl <jan.mottl@ackee.cz>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant