Plugin Services - Getting started

I'm developing a basic plugin that hooks into the Action Menu. Having read the getting started guide https://www.jetbrains.org/intellij/sdk/docs/basics.html I got a working prototype by extending `AnAction`. I then decided to move the business logic of my plugin into a dedicated service. Based on the documentation regarding plugin services https://www.jetbrains.org/intellij/sdk/docs/basics/plugin_structure/plugin_services.html I registered my new service as an application service in the plugin.xml. This worked great until I needed to add a dependency to my service. The dependency has a static factory method that needs to be called to initialise it rather than using the constructor however there doesn't seem to be a way in the plugin.xml to add an application service and specify this static factory method. This is achieved in the PHP framework Symfony like so https://symfony.com/doc/current/service_container/factories.html. Is this possible from the plugin.xml or should I be doing this differently?

Here's an example of such a dependency where the `createDefault()` method should be used by the ServiceManager.

public class Plugin
{
private IdeaPluginDescriptor pluginDescriptor;


public Plugin(IdeaPluginDescriptor pluginDescriptor)
{
this.pluginDescriptor = pluginDescriptor;
}


@NotNull
public static Plugin createDefault()
{
return new Plugin(PluginManager.getPlugin(PluginId.getId("my-plugin-id")));
}


@NotNull
public String issueTracker()
{
return this.pluginDescriptor.getVendorUrl().concat("/issues");
}
}
0
1 comment

Can you please explain what are you trying to do?

Service is a singleton for app, project  or module. What do you mean by createDefault in context of service? 

If you are planning to have multiple instances of your Plugin - your factory is a service, not plugin. 

0

Please sign in to leave a comment.