Skip to content

Instantly share code, notes, and snippets.

@dnys1
Created November 1, 2023 14:28
Show Gist options
  • Save dnys1/5b4bed3f39b4ff3f6a9c00f1e55b1941 to your computer and use it in GitHub Desktop.
Save dnys1/5b4bed3f39b4ff3f6a9c00f1e55b1941 to your computer and use it in GitHub Desktop.
primal-lantern-1698
class ServiceManager {
final _instances = <Type, Object>{};
void register<T extends Object>(T instance) {
_instances[T] = instance;
}
bool isRegistered<T extends Object>() {
return isRegisteredByType(T);
}
bool isRegisteredByType(Type type) {
return _instances.containsKey(type);
}
}
final types = <Type>[
String,
int,
];
void main() {
final sm = ServiceManager();
sm.register('hello');
for (final type in types) {
print('$type: ${sm.isRegisteredByType(type)}');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment