[ 
https://issues.apache.org/jira/browse/SLING-11849?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17716762#comment-17716762
 ] 

Stefan Seifert commented on SLING-11849:
----------------------------------------

the usual way in OSGi to unregister a service is to call the {{unregister}} 
methods on the service registration instance.
context.registerService is just a convenience method and does not return the 
service registration, but the registered service instance.
in case you need to unregister a service in the unit test (i think that does 
happen only in rare cases), register the service directly via 
context.bundleContext() and keep the reference to the service registration.

> Create osgiContext#unregisterService() for easy unregistering of services
> -------------------------------------------------------------------------
>
>                 Key: SLING-11849
>                 URL: https://issues.apache.org/jira/browse/SLING-11849
>             Project: Sling
>          Issue Type: Improvement
>          Components: Testing
>    Affects Versions: Testing OSGi Mock 3.3.6
>            Reporter: Henry Kuijpers
>            Priority: Major
>
> Since we can do:
> {code:java}
> this.underTest = context.registerInjectActivateService(Test.class);
> {code}
> it would be very useful if we can also do:
> {code:java}
> context.unregisterService(this.underTest);
> {code}
> for example.
> It would be very convenient to do this, since the OSGi Mock API is easy and 
> simple to write and to be able to unregister services, it would be needed to 
> have a ServiceRegistration<Test> and also a ServiceReference<Test> to be able 
> to call .unregister() on it
> If we add this method, then all this logic can be put in this method.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to