configure method

  1. @override
FutureOr<void> configure(
  1. ConfigurableScope scope
)
override

configure is used to configure scope synchronously or asynchronously.

Return void if it's synchronous configuration:

class SyncConfigurable implements Configurable {

  @override
  FutureOr<void> configure(ConfigurableScope scope) {
    final repository = Repository();
    scope.expose<Repository>(expose: () => repository);
  }
}

Return Future<void> if it's asynchronous configuration:

class AsyncConfigurable implements Configurable {

  @override
  FutureOr<void> configure(...) async { // use `async` here
    // use `await` here
    final repository = await createRepositoryAsync();
    scope.expose<Repository>(expose: () => repository);
  }
}

When all configurations are synchronous, scope will be returned synchronously:

final scope = Scope.root([
  SyncConfigurable(), // use sync configuration
]) as Scope;          // return `Scope`

When one of configurations is asynchronous, scope will be returned asynchronously:

final scope = Scope.root([
  AsyncConfigurable(),  // use async configuration
]) as Future<Scope>;    // return `Future<Scope>`

Implementation

@override
FutureOr<void> configure(ConfigurableScope scope) {
  final configure = combine();
  return configureScope(configure, scope);
}