简体   繁体   中英

Eclipse extension points vs manual programmatic access

To reference services exposed by one plugin into another Eclipse Plugin I have two ways

1.)Extension Points (complicated)

2.)Just use BundleContext get List of Bundles and then access your other Eclipse Plugin through ServiceReference and call respective services (very easy)

I can see that 2 is far more easier than 1.)

So is 2 the right way?

Why was 1.) invented then?

Neither (1) nor (2) are correct.

(1) simply has nothing to do with OSGi Services. It's an entirely different use-case.

(2) you have made far more complicated than necessary. You just need to use Declarative Services to obtain a reference to the service that you want to use. Do NOT go to the bundle that publishes the service, because you shouldn't know or care which bundle is the source of the service.

You can find here a good comparison of extensions and OSGi-services. There is no right or wrong (IMHO the extension point mechanism is not complicated, the tooling is better,...), in some scenarios the one is better in some the other. Eclipse was in its early versions not based on OSGi so the OSGi-way is available since Eclipse 3.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM