Google is committed to advancing racial equity for Black communities. See how.

exposeServiceProvider<T extends Service> method

void exposeServiceProvider <T extends Service>(ServiceProvider<T> serviceProvider, ServiceData<T> serviceData)

Similar to #exposeService but instead of passing the service implementation directly, pass a provider function that can be invoked asynchronously, when a request is received, to provide the service implementation at run time.

serviceData can be found as part of the generated FIDL bindings, it holds the service runtime name and bindings object used for establishing a connection.

ServiceProvider is defined as follows:

typedef ServiceProvider<T> = FutureOr<T> Function();

Where T represents the service type.

Usage example:

import 'package:fidl_fuchsia_foo/fidl_async.dart' as fidl;
import 'package:fuchsia_modular/agent.dart';
import 'src/foo_service_impl.dart';

void main(List<String> args) {
  Agent().exposeServiceProvider(getService, fidl.FooServiceData());

FutureOr<FooServiceImpl> getService() {
  // do something fancy here
  return FooServiceImpl();

class FooServiceImpl extends fidl.FooService { ... }


void exposeServiceProvider<T extends Service>(
    ServiceProvider<T> serviceProvider, ServiceData<T> serviceData);