ServiceHost class

Hosts services and provides dependency injection.

There can only be one ServiceHost in an application. Use this code in your main function:

await ServiceHost([() => ServiceA(), () => ServiceB()]).run();

This should not be confused with the IoC container provided by the client library cl_appbase. While providing a similar pattern for dependency injection, this class also controls the execution of the application itself, providing a framework for services to live in.

Constructors

ServiceHost(List<BaseService Function()> factories, {bool catchSignal = true, bool failWithServices = true, LogBackend? logBackend, Function? onInitialized, List<String> args = const <String>[], Map<String, dynamic> config = const <String, dynamic>{}})
Creates a ServiceHost instance.
factory

Properties

catchSignal bool
final
failWithServices bool
final
hashCode int
The hash code for this object.
no setterinherited
onInitialized Function?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
resolveService<TService>() → TService
run([CancellationToken? cancel]) Future<void>
Runs the application.
toString() String
A string representation of this object.
inherited
tryResolveService<TService>() → TService?

Operators

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

Static Methods

resolve<TService>() → TService
tryResolve<TService>() → TService?