ServiceHost class

IoC container

Register a service:

ServiceHost().register(MyServiceImpl());

Receive a service:

final myService = ServiceHost().get<MyServiceImpl>();

After registering one or more services, initializeServices must be called before receiving one of the newly registered service instances.

Interfaces for services can be used to enable switching out Service implementations more easily.

Register a service with interface:

ServiceHost().register<MyService>(MyServiceImpl());

Receiving a service via interface class:

// returns the MyServiceImpl from above example
final myService = ServiceHost().get<MyService>();

Services and interfaces must implement or extend abstract class Service.

Constructors

ServiceHost()
factory

Properties

hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

contains<T>() bool
Returns true if a service of type T is registered.
dispose<T>() Future<void>
Disposes and removes the service registered for type T from the host.
get<T extends Service>() → T
Returns the registered service implementation for type T.
initializeServices() Future<void>
Initializes all un-initialized registered services.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
register<T extends Service>(T impl) → void
Registers a service implementation for type T.
toString() String
A string representation of this object.
inherited

Operators

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