Skip to content

Instantly share code, notes, and snippets.

@georgelesica-wf
Created April 4, 2018 23:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save georgelesica-wf/c8a3bf9cf57da376440d5e275a6f3e2e to your computer and use it in GitHub Desktop.
Save georgelesica-wf/c8a3bf9cf57da376440d5e275a6f3e2e to your computer and use it in GitHub Desktop.
List<dynamic> _stuff = [];
void inject(dynamic thing) {
_stuff.add(thing);
}
T request<T>() => _stuff.firstWhere((thing) => thing is T, orElse: () => null);
class MyThing {
final String value = 'hello, world';
}
void main() {
inject(new MyThing());
var thing = request<MyThing>();
print(thing.value);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment