RpcModule class abstract

Shared lifecycle base for all framework modules.

Subclass RpcServerModule to expose RPC services. Use RpcModule directly for everything else: infrastructure that registers shared DI bindings (a database pool other modules depend on), or a client that connects to a remote service with RpcClientConnection in onStart and onStop.

Startup order

Declare dependencies to guarantee ordering. If module B declares List<Type> get dependencies => [A], the framework starts A before B and stops B before A. Circular or missing dependencies throw RpcStatusException (FAILED_PRECONDITION).

Example — infrastructure module

class DatabaseModule extends RpcModule {
  @override
  String get name => 'DatabaseModule';

  @override
  void configureWithEnv(RpcContainer c, RpcEnvConfig env) {
    c.registerSingleton<DbPool>(DbPool(env.require('DATABASE_URL')));
  }

  @override
  Future<RpcHealthStatus?> checkHealth() async {
    final ok = await _pool.ping();
    return ok
      ? RpcHealthStatus.healthy(component: name, message: 'db ok')
      : RpcHealthStatus.unhealthy(component: name, message: 'db unreachable');
  }
}
Implementers

Constructors

RpcModule()

Properties

dependencies → List<Type>
Module types that must be configured and started before this module.
no setter
hashCode → int
The hash code for this object.
no setterinherited
name → String
Human-readable module name used in logs and health reports.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

checkHealth() → Future<RpcHealthStatus?>
Returns a health status for this module, or null to skip health reporting.
configure(RpcContainer container) → void
Register services into container.
configureWithEnv(RpcContainer container, RpcEnvConfig env) → void
Register environment-dependent services into container.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
onStart(RpcContainer container) → Future<void>
Called after every module is configured and before the server accepts a connection, in dependency order.
onStop() → Future<void>
Called after the server has stopped and drained, in reverse dependency order, so a handler still running could use what the module holds.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited