How to manage the lifecycle of application service?

I've tried to implement ApplicationComponent, org.picocontainer.{Startable, Disposible}

5 comments

I'm not sure what you want to achieve. If you implement the ApplicationComponent interface and register your class as a component, it will be created at application startup time and stopped at its shutdown. If you want your class to be created on demand but need to perform some handling on its shutdown, you need to register it as a service, perform the initialization in its constructor and implement the com.intellij.openapi.Disposable interface. The Startable and Disposable interfaces from picocontainer aren't used by our plugin framework.

0

com.intellij.openapi.Disposable works.

Thank you so much.

btw. There should be a unified api for componet and service.

IL

0

The Disposable API does work for both components and services.

0

How about start/init? more clear lifecycle?

Service is just a Component, so it should implement ComponentBase

Maybe jetbrains has thinked about to change the whole container. It's not easy.



IL

0

The initialization of a service is performed in the constructor. There is  no need to provide any additional initialization methods.

Implementing the ComponentBase interface is optional for application or project components, and is very often not needed.

We do not have any plans to change the component model of IntelliJ IDEA.

0

Please sign in to leave a comment.