Make custom app API available via custom provider

Hej there,

currently I have a thought about how an app could make an API available for other apps to implement. For example the Maps app could make it possible for other apps, that they provide locations to show in the Maps app. Something like the Unified Search where you implement the interface for the search provider and register your own provider on booting.

What is the best way to do this? Check if the needed interface is defined and then include the provider for your own app? Or is there something I haven’t seen yet?

I have thought about something like the following:

function getMapsContext( OCP\IContainer $container ): ?OCA\Maps\IRegistraionContext {
  if ( !class_exists( 'OCA\\Maps\\ILocationProvider' ) ) {
    return null;
  }

  return $container->query( OCA\Maps\IRegistrationContext::class );
}

function registerLocationProvider(  OCP\IContainer $container ): void {
  $context = $this->getMapsContext( $container );

  if ( $context === null ) {
    return;
  }

  $context->registerLocationProvider(
    OCA\MyApp\MapsLocationProvider::class
  );
}

Thanks so far!