provideType<T extends Object> method
Finds and returns an object instance provided for a type token
.
A runtime assertion is thrown in debug mode if:
T
is explicitly or implicitly bound todynamic
.- If
T
is notObject
, the DItoken
is not the same asT
.
An error is thrown if a provider is not found.
Implementation
@nonVirtual
T provideType<T extends Object>(Type token) {
// NOTE: It is not possible to design this API in such a way that only "T"
// can be used, and not require "token" as well. Our injection system
// currently uses "identical" (similar to JS' ===), and the types passed
// through "T" are not canonical (they are == equivalent, but not ===).
//
// See historic discussion here: dartbug.com/35098
assert(T != dynamic, 'Returning a dynamic is not supported');
return unsafeCast(get(token));
}