MCPcopy
hub / github.com/guardicore/monkey / resolve

Method resolve

monkey/common/di_container.py:111–130  ·  view source on GitHub ↗

Resolves all dependencies and returns a new instance of `type_` using constructor dependency injection. Note that only positional arguments or arguments with defaults are resolved. Varargs and keyword-only args are ignored. Dependencies are resolved with the followi

(self, type_: Type[T])

Source from the content-addressed store, hash-verified

109
110 @no_type_check
111 def resolve(self, type_: Type[T]) -> T:
112 """
113 Resolves all dependencies and returns a new instance of `type_` using constructor dependency
114 injection. Note that only positional arguments or arguments with defaults are resolved.
115 Varargs and keyword-only args are ignored.
116
117 Dependencies are resolved with the following precedence
118
119 1. Conventions
120 2. Types, Instances
121
122 :param **type_**: A `type` (class) to construct
123 :return: An instance of **type_**
124 :raises UnresolvableDependencyError: If any dependencies could not be successfully resolved
125 """
126 with suppress(UnresolvableDependencyError):
127 return self._resolve_type(type_)
128
129 args = self.resolve_dependencies(type_)
130 return type_(*args)
131
132 def resolve_dependencies(self, type_: Type[T]) -> Sequence[Any]:
133 """

Calls 2

_resolve_typeMethod · 0.95
resolve_dependenciesMethod · 0.95

Tested by

no test coverage detected