def resolve(self, key: Any) -> Any:
if key not in self._singletons:<EOL><INDENT>if key in self._factories:<EOL><INDENT>factory = self._factories[key]<EOL>result = factory(self)<EOL>if isinstance(factory, SingletonFactory):<EOL><INDENT>self._singletons[key] = result<EOL><DEDENT>return result<EOL><DEDENT>elif isinstance(type(key), type):<EOL><INDENT>result = self._resolve_class(key)<EOL>self._singletons[key] = result<EOL>return result<EOL><DEDENT>else:<EOL><INDENT>msg = '<STR_LIT>' % key<EOL>raise ResolveException(msg)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return self._singletons[key]<EOL><DEDENT>
Fetches an instance or creates one using the registered factory method
:argument key the key to look up
:return the created or looked up instance