Created with <3 with dartpad.dev.
Created
November 1, 2023 14:28
-
-
Save dnys1/5b4bed3f39b4ff3f6a9c00f1e55b1941 to your computer and use it in GitHub Desktop.
primal-lantern-1698
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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