bigdataviewer/bigdataviewer-playground

add getCommandService() to SourceAndConverterService

Closed this issue · 4 comments

@NicoKiaru

Do you think it could make sense to add a method
getCommandService() to SourceAndConverterService ?
I holds a reference to it anyway, and it would be convenient to access it to launch modules using commandService.run(...).

I'm not a fan of this. If you really want a convenient static access to a command service, you can create your own service:

@Plugin(type = Service.class, headless = true)
public class StaticServiceAccess extends AbstractService implements
	SciJavaService
{

	@Parameter
	CommandService commandService;

        @Override
	public void initialize() {
		MyStaticClassWhereINeedACommandService.commandService = commandService;
        }

}

However, I think moving from our weird 'action' classes to an all static API, like BdvFunctions would be nice. I don't like the current complexity of the API.

Like QuPath, classes with static builders would be my preferred choice.

Interesting!

So that class would be automatically initialized upon net.imagej startup?

So that class would be automatically initialized upon net.imagej startup?

The class MyStaticClassWhereINeedACommandService ? Probably. It's what we are doing here:

SourceAndConverterServices.setSourceAndConverterService(this);

Works like a charm!
Thanks!

@Plugin(type = Service.class, headless = true)
public class Services extends AbstractService implements SciJavaService
{
	public static CommandService commandService;

	@Parameter
	CommandService cmd;

	@Override
	public void initialize() {
		commandService = cmd;
	}
}