glorpen.di API Documentation¶
glorpen.di¶
Dependency injection component.
-
glorpen.di.__version__¶ Current package version.
-
class
glorpen.di.Container[source]¶ Alias to
glorpen.di.container.Container.
glorpen.di.container¶
-
class
glorpen.di.container.Container[source]¶ Implementation of DIC container.
-
add_service(name)[source]¶ Adds service definition to this container.
name argument should be a class, import path, or string if
Service.implementation()will be used.- Returns:
Service
-
set_scope_hierarchy(*scopes)[source]¶ Sets used scopes hierarchy.
Arguments should be scopes sorted from widest to narrowest. A service in wider scope cannot request service from narrower one.
Default is: [
glorpen.di.scopes.ScopeSingleton,glorpen.di.scopes.ScopePrototype].- Args:
- classes or instances of
glorpen.di.scopes.ScopeBase
-
-
class
glorpen.di.container.Deffered(service=None, method=None, param=None)[source]¶ Class for marking values for lazy resolving.
Values are resolved by
Containerupon service creation.
-
class
glorpen.di.container.Service(name_or_impl)[source]¶ Service definition.
When filling arguments for constructor and method calls you can use:
- my_var__svc=MyClass - will inject service MyClass to my_var
- my_var__param=”my.param” - will inject parameter named “my.param” to my_var
Implementation value for service can be:
- class instance
- string with import path
- callable
-
call(method, kwargs=None, **kwargs_inline)[source]¶ Adds a method call after service creation with given arguments.
- Returns:
Service
-
call_with_signature(method, kwargs=None, **kwargs_inline)[source]¶ Adds a method call after service creation with given arguments. Arguments detected from function signature are added if not already present.
- Returns:
Service
-
configurator(service=None, method=None, callable=None, kwargs=None, **kwargs_inline)[source]¶ Adds service or callable as configurator of this service.
- Args:
- service + method, callable: given service method/callable will be called with instance of this service.
- Returns:
Service
-
factory(service=None, method=None, callable=None, kwargs=None, **kwargs_inline)[source]¶ Sets factory callable.
- Returns:
Service
-
kwargs_from_signature()[source]¶ Adds arguments found in class signature, based on provided function hints.
- Returns:
Service
glorpen.di.scopes¶
Built-in scopes.
glorpen.di.exceptions¶
Exceptions used by glorpen.di.
-
exception
glorpen.di.exceptions.InjectionException(svc_name, cls, method_name=None)[source]¶ Raised when service or its method cannot be created or called
-
exception
glorpen.di.exceptions.InvalidAliasTargetException(name)[source]¶ Raised when adding alias to alias or not exisiting service
-
exception
glorpen.di.exceptions.RecursionException(s_def, requester_chain)[source]¶ Raised when service definition is requiring itself.
-
exception
glorpen.di.exceptions.ScopeWideningException(s_def, requester_chain)[source]¶ Raised when Service A depends on Service B from narrower scope.
-
exception
glorpen.di.exceptions.ServiceAlreadyCreated(svc_name)[source]¶ Raised when service definition is changed but service is already created by
glorpen.di.container.Container.
-
exception
glorpen.di.exceptions.UnknownParameterException(name)[source]¶ Raised when requesting parameter which is not registered in
glorpen.di.container.Container.
-
exception
glorpen.di.exceptions.UnknownScopeException(scope, svc_name)[source]¶ Raised when service has scope not assigned to
glorpen.di.container.Containerbyglorpen.di.container.Container.set_scope_hierarchy().
-
exception
glorpen.di.exceptions.UnknownServiceException(svc_name)[source]¶ Raised when requesting service name which is not registered in
glorpen.di.container.Container.