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
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
valuein the place of its type, when that type is registered and not overridden. Dox calls it for the services ofAppConfig.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
Tis turned into aTwithfind.lib/generated/container.g.dartcalls this for every@DoxModel.Route.bindwins 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
Ton every get. -
get<
T extends Object> () → T -
The instance of
T. Throws a StateError whenTis not registered. -
getByType(
Type type) → Object -
The instance of
type. Same as get, for a Type value. -
has<
T extends Object> () → bool -
True when
Tis registered. -
instance<
T extends Object> (T value) → void -
valueis the instance ofT. Use it for config values. -
True when
typegives 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
Twithvalue, 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 -
Tis a router. Dox registers its routes at start.lib/generated/container.g.dartcalls this for every class that extendsRouter. -
service<
T extends DoxService> (IocFactory< T> make) → void -
Tis a service. Dox runs itssetup()at start, in every isolate.lib/generated/container.g.dartcalls this for every class that implementsDoxService. -
singleton<
T extends Object> (IocFactory< T> make) → void -
One instance of
Tper 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(likeUserService), 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