-
Enhancement
-
Resolution: Done
-
Major
-
26.0.0.Final
-
None
Subsystem developers wanting to use ValueRegistry to capture service values via ServiceInstaller.Builder.withCaptor(...) current lack a facility to remove the associated registry entry on service removal.
e.g.
ServiceInstaller installer = ServiceInstaller.builder(...).withCaptor(registry.add(...)).build();
Currently, one must resort to a verbosely decorating the result of Installer.install() in order to add service removal behavior.
e.g.
ResourceServiceInstaller installer = ServiceInstaller.builder(...).withCaptor(registry.add(...)).build(); ResourceServiceInstaller decorator = new ResourceServiceInstaller() { Consumer<OperationContext> remover = ctx -> registry.remove(ctx.getCurrentAddressValue()); return new ResourceServiceInstaller() { @Override public Consumer<OperationContext> install(OperationContext context) { return installer.install(context).andThen(remover); } } }
It would more user friendly to be able to add this behavior via the ServiceInstaller.Builder itself, e.g.:
ServiceInstaller installer = ServiceInstaller.builder(...) .withCaptor(registry.add(...)) .onRemove(() -> registry.remove(...)) .build();