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

Add bean/module destructor for Annotation-defined bean/module #112

Open
vdshb opened this issue Jan 28, 2024 · 1 comment
Open

Add bean/module destructor for Annotation-defined bean/module #112

vdshb opened this issue Jan 28, 2024 · 1 comment
Labels
status:checking Ticket is currently being checked type:feature-request
Milestone

Comments

@vdshb
Copy link

vdshb commented Jan 28, 2024

Is your feature request related to a problem? Please describe.

My bean is defined with annotation:

@Module
class AppModule {
  @Single(createdAtStart = true)
  fun sqlDriver() : SqlDriver {
    //...
  }
}

I want to define bean/module close strategy to it.
Effecitvely I want to run sqlDriver.close() during KoinApplication::close call.

Describe the solution you'd like
The design might be something like this:

@Module
class AppModule {
  @Single(createdAtStart = true)
  fun sqlDriver() : SqlDriver {
    //...
  }
  @OnClose
  fun closeModule(sqlDriver: SqlDriver) {
    sqlDriver.close()
  }
}

Describe alternatives you've considered
If bean is AutoClosable the bonus design might be something like this:

@OnClose(closeAutoClosable = true)
@Single(createdAtStart = true)
fun sqlDriver() : SqlDriver {
  //...
}

But conflicts resolution strategy with @OnClose and close order of dependant beans must be designed additionally.

Target Koin project
Koin-Annotations

@arnaudgiuliani
Copy link
Member

yes, definitely need to propose around closing definitions with onClose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:checking Ticket is currently being checked type:feature-request
Projects
None yet
Development

No branches or pull requests

2 participants