Ticket #695 (closed Enhancement: fixed)

Opened 10 years ago

Last modified 10 years ago

Plugin framework: inject service dependencies

Reported by: jri Owned by: jri
Priority: Major Milestone: Release 4.4
Component: DeepaMehta Standard Distribution Version: 4.3
Keywords: Cc: dgf, Malte, carolina
Complexity: 3 Area: Application Framework / API
Module: deepamehta-core

Description

To consume services a plugin developer should not be required to supply boilerplate code (serviceArrived and serviceGone hooks). Instead the consumed services should be injected into the plugin automatically.

Change History

comment:1 Changed 10 years ago by jri

  • Status changed from new to accepted

comment:2 Changed 10 years ago by Jörg Richter

Core: inject service dependencies (#695).

BREAKING CHANGE

A plugin gets the plugin services it consumes via injection. There is a new @Inject annotation.

So, the plugin developer is no longer required to supply the boilerplate code (serviceArrived and serviceGone hooks). These 2 hooks and the @ConsumesService? annotation are obsolete.

Old pattern (example):

import de.deepamehta.core.service.PluginService;
import de.deepamehta.core.service.annotation.ConsumesService;

public class YourPlugin ... {

    private TopicmapsService topicmapsService;
    private FacetsService facetsService;

    @Override
    @ConsumesService({TopicmapsService.class, FacetsService.class})
    public void serviceArrived(PluginService service) {
        if (service instanceof FacetsService) {
            facetsService = (FacetsService) service;
        } else if (service instanceof TopicmapsService) {
            topicmapsService = (TopicmapsService) service;
        }
    }

    @Override
    public void serviceGone(PluginService service) {
        if (service == facetsService) {
            facetsService = null;
        } else if (service == topicmapsService) {
            topicmapsService = null;
        }
    }
}

New pattern (example):

import de.deepamehta.core.service.Inject;

public class YourPlugin ... {

    @Inject
    private TopicmapsService topicmapsService;

    @Inject
    private FacetsService facetsService;
}

See #695.

comment:3 Changed 10 years ago by Jörg Richter

comment:4 Changed 10 years ago by Jörg Richter

Core: inject service dependencies (#695).

BREAKING CHANGE

A plugin gets the plugin services it consumes via injection. There is a new @Inject annotation.

So, the plugin developer is no longer required to supply the boilerplate code (serviceArrived and serviceGone hooks). These 2 hooks and the @ConsumesService? annotation are obsolete.

Old pattern (example):

import de.deepamehta.core.service.PluginService;
import de.deepamehta.core.service.annotation.ConsumesService;

public class YourPlugin ... {

    private TopicmapsService topicmapsService;
    private FacetsService facetsService;

    @Override
    @ConsumesService({TopicmapsService.class, FacetsService.class})
    public void serviceArrived(PluginService service) {
        if (service instanceof FacetsService) {
            facetsService = (FacetsService) service;
        } else if (service instanceof TopicmapsService) {
            topicmapsService = (TopicmapsService) service;
        }
    }

    @Override
    public void serviceGone(PluginService service) {
        if (service == facetsService) {
            facetsService = null;
        } else if (service == topicmapsService) {
            topicmapsService = null;
        }
    }
}

New pattern (example):

import de.deepamehta.core.service.Inject;

public class YourPlugin ... {

    @Inject
    private TopicmapsService topicmapsService;

    @Inject
    private FacetsService facetsService;
}

See #695.

comment:5 Changed 10 years ago by Jörg Richter

comment:6 Changed 10 years ago by Jörg Richter

Core: inject service dependencies (#695).

BREAKING CHANGE

A plugin gets the plugin services it consumes via injection. There is a new @Inject annotation.

So, the plugin developer is no longer required to supply the boilerplate code (serviceArrived and serviceGone hooks). These 2 hooks and the @ConsumesService? annotation are obsolete.

Old pattern (example):

import de.deepamehta.core.service.PluginService;
import de.deepamehta.core.service.annotation.ConsumesService;

public class YourPlugin ... {

    private TopicmapsService topicmapsService;
    private FacetsService facetsService;

    @Override
    @ConsumesService({TopicmapsService.class, FacetsService.class})
    public void serviceArrived(PluginService service) {
        if (service instanceof FacetsService) {
            facetsService = (FacetsService) service;
        } else if (service instanceof TopicmapsService) {
            topicmapsService = (TopicmapsService) service;
        }
    }

    @Override
    public void serviceGone(PluginService service) {
        if (service == facetsService) {
            facetsService = null;
        } else if (service == topicmapsService) {
            topicmapsService = null;
        }
    }
}

New pattern (example):

import de.deepamehta.core.service.Inject;

public class YourPlugin ... {

    @Inject
    private TopicmapsService topicmapsService;

    @Inject
    private FacetsService facetsService;
}

See #695.

comment:7 Changed 10 years ago by Jörg Richter

comment:8 Changed 10 years ago by Jörg Richter

Core: reintroduce service hooks (#695).

The serviceArrived() and serviceGone() hooks are back.

Note: these hooks are *not* required to actually consume a service as this is done by injection now. Most (service consuming) plugins are not required to implement these hooks.

However, these hooks are still useful when a plugin needs to do some work just in the moment when a service becomes available resp. is about to go away.

The hook signatures are the same as they were in DM 4.3

See #695.

comment:9 Changed 10 years ago by Jörg Richter

Box Renderer: fix unregistering (#695).

When the Box Renderer bundle stops no NullPointerException? is thrown.
The viewmodel customizer is unregistered properly.

See #695.

comment:10 Changed 10 years ago by Jörg Richter

Core: reintroduce service hooks (#695).

The serviceArrived() and serviceGone() hooks are back.

Note: these hooks are *not* required to actually consume a service as this is done by injection now. Most (service consuming) plugins are not required to implement these hooks.

However, these hooks are still useful when a plugin needs to do some work just in the moment when a service becomes available resp. is about to go away.

The hook signatures are the same as they were in DM 4.3

See #695.

comment:11 Changed 10 years ago by Jörg Richter

Box Renderer: fix unregistering (#695).

When the Box Renderer bundle stops no NullPointerException? is thrown.
The viewmodel customizer is unregistered properly.

See #695.

comment:12 Changed 10 years ago by Jörg Richter

Core: reintroduce service hooks (#695).

The serviceArrived() and serviceGone() hooks are back.

Note: these hooks are *not* required to actually consume a service as this is done by injection now. Most (service consuming) plugins are not required to implement these hooks.

However, these hooks are still useful when a plugin needs to do some work just in the moment when a service becomes available resp. is about to go away.

The hook signatures are the same as they were in DM 4.3

See #695.

comment:13 Changed 10 years ago by Jörg Richter

Box Renderer: fix unregistering (#695).

When the Box Renderer bundle stops no NullPointerException? is thrown.
The viewmodel customizer is unregistered properly.

See #695.

comment:14 Changed 10 years ago by jri

  • Status changed from accepted to closed
  • Resolution set to fixed
Note: See TracTickets for help on using tickets.