Register PersistentStateComponents dynamically?

Is it possible to register PersistentStateComponents dynamically, for example from an application component at startup, instead of specifying them as e.g. project components in plugin.xml? I'm using Clojure and I'd rather avoid having to AOT compile to generate a named class if possible.

5 comments
Comment actions Permalink

A PersistentStateComponent does not need any registration by itself; this interface needs to be implemented by a service or component class. You can register a service dynamically, but I don't quite understand how you plan to access it from other parts of your plugin after you do that.

By the way, from the performance point of view, it's strongly recommended to register services and other extensions directly in plugin.xml, because it will ensure that your classes are loaded on demand and don't cause any performance impact when the user has your plugin installed but does not use it in a specific session.

0
Comment actions Permalink

Well, I guess I can generate a class that implements PersistentStateComponent dynamically, and then use that to register a service and retrieve it later with ServiceManager.getService(). How would I register the service as a project level service, i.e. something that I might use for persisting project-level configuration settings?

0
Comment actions Permalink

Hmm, I just saw your edit about performance. When are classes for a particular plugin loaded, then? When they're requested from the IoC container? Does this apply to all classes in the <extensions> section of the plugin.xml? I assume some of them must be loaded whether the plugin is used or not (things like fileTypeFactory and actions)?

0
Comment actions Permalink

Service classes are loaded when the code of your plugin requests them. Extension classes are normally loaded when requested by the core (normally when the specific feature is triggered; some extensions like fileTypeFactory are indeed requested during IDE startup). Actions are always loaded (by a background thread which is spawned after the project opening completes).

0
Comment actions Permalink

Ok, thanks Dmitry - I'll have to think about how to structure things then.

0

Please sign in to leave a comment.