IocContainer class

The Dox container. It makes your classes and gives their constructors what they need.

You do not fill it by hand. Put @Inject() above a class, run dart run build_runner build, and set AppConfig(container: registerContainer) from lib/generated/container.g.dart.

Each isolate has its own container (Dox().ioc), so a singleton is one instance per isolate. It is made on first use.

UserService users = Dox().ioc.get<UserService>();

Constructors

IocContainer()

Properties

hashCode → int
The hash code for this object.
no setterinherited
routers → List<Router>
The routers, made from the container, in the order they were added.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
services → List<DoxService>
The services, made from the container, in the order they were added.
no setter

Methods

adopt(Object value) → void
Put value in the place of its type, when that type is registered and not overridden. Dox calls it for the services of AppConfig.services, so the container gives the same instance.
bindModel<T extends Object>(RouteBinder<T> find) → void
A route param for a controller parameter of type T is turned into a T with find. lib/generated/container.g.dart calls this for every @DoxModel. Route.bind wins over it.
clear() → void
Remove every registration, but not the overrides. Dox().initialize() calls it before it registers the app classes.
clearOverrides() → void
Remove every override. The next Dox().initialize() registers the real classes again.
factory<T extends Object>(IocFactory<T> make) → void
A new instance of T on every get.
get<T extends Object>() → T
The instance of T. Throws a StateError when T is not registered.
getByType(Type type) → Object
The instance of type. Same as get, for a Type value.
has<T extends Object>() → bool
True when T is registered.
instance<T extends Object>(T value) → void
value is the instance of T. Use it for config values.
isShared(Type type) → bool
True when type gives the same instance every time.
modelBinderNamed(String name) → RouteBinder<Object>?
The bindModel binder for the type named name, or null.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
override<T extends Object>(T value) → void
Replace T with value, eg. a fake in a test. It stays when the app registers its classes again (Dox().initialize()), until clearOverrides. Call it before the server starts: a controller gets its objects once, at start.
router<T extends Router>(IocFactory<T> make) → void
T is a router. Dox registers its routes at start. lib/generated/container.g.dart calls this for every class that extends Router.
service<T extends DoxService>(IocFactory<T> make) → void
T is a service. Dox runs its setup() at start, in every isolate. lib/generated/container.g.dart calls this for every class that implements DoxService.
singleton<T extends Object>(IocFactory<T> make) → void
One instance of T per container (per isolate), made on first use.
toString() → String
A string representation of this object.
inherited
typeNamed(String name) → Type?
The registered type with the name name (like UserService), or null. Throws a StateError when two types have this name. Dox uses it at start to read controller parameters. Not for the request path: it is slow.

Operators

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