# cpl_core.dependency_injection package

## Submodules

## cpl_core.dependency_injection.scope module

class cpl_core.dependency_injection.scope.Scope(service_provider: ServiceProviderABC )

  Bases: `ScopeABC`

  dispose()

    Sets service_provider to None

  property service_provider: ServiceProviderABC

    Returns to service provider of scope

    Returns:

      Object of type `cpl_core.dependency_injection.service_provider_abc.ServiceProviderABC`

## cpl_core.dependency_injection.scope_abc module

class cpl_core.dependency_injection.scope_abc.ScopeABC

  Bases: `ABC`

  ABC for the class `cpl_core.dependency_injection.scope.Scope`

  abstract dispose()

    Sets service_provider to None

  abstract property service_provider

    Returns to service provider of scope

    Returns:

      Object of type `cpl_core.dependency_injection.service_provider_abc.ServiceProviderABC`

## cpl_core.dependency_injection.scope_builder module

class cpl_core.dependency_injection.scope_builder.ScopeBuilder(service_provider: ServiceProviderABC )

  Bases: `object`

  Class to build `cpl_core.dependency_injection.scope.Scope`

  build() → ScopeABC

    Returns scope

    Returns:

      Object of type `cpl_core.dependency_injection.scope.Scope`

## cpl_core.dependency_injection.service_collection module

class cpl_core.dependency_injection.service_collection.ServiceCollection(config: ConfigurationABC )

  Bases: `ServiceCollectionABC`

  Representation of the collection of services

  add_db_context(db_context_type: Type[ DatabaseContextABC ], db_settings: DatabaseSettings )

    Adds database context

    Parameter:
      db_context: Type[`cpl_core.database.context.database_context_abc.DatabaseContextABC`]

        Database context

  add_logging()

    Adds the CPL internal logger

  add_pipes()

    Adds the CPL internal pipes as transient

  add_scoped(service_type: T, service: Optional[Callable] = None)

    Adds a service with scoped lifetime

    Parameter:
      service_type: `Type`

        Type of the service

      service: `Callable`

        Object of the service

    Returns:

      self: `cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC`

  add_singleton(service_type: T, service: Optional[T] = None)

    Adds a service with singleton lifetime

    Parameter:
      service_type: `Type`

        Type of the service

      service: `Callable`

        Object of the service

    Returns:

      self: `cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC`

  add_transient(service_type: T, service: Optional[T] = None)

    Adds a service with transient lifetime

    Parameter:
      service_type: `Type`

        Type of the service

      service: `Callable`

        Object of the service

    Returns:

      self: `cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC`

  build_service_provider() → ServiceProviderABC

    Creates instance of the service provider

    Returns:

      Object of type `cpl_core.dependency_injection.service_provider_abc.ServiceProviderABC`

## cpl_core.dependency_injection.service_collection_abc module

class cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC

  Bases: `ABC`

  ABC for the class `cpl_core.dependency_injection.service_collection.ServiceCollection`

  abstract add_db_context(db_context_type: Type[ DatabaseContextABC ], db_settings: DatabaseSettings )

    Adds database context

    Parameter:
      db_context: Type[`cpl_core.database.context.database_context_abc.DatabaseContextABC`]

        Database context

  add_discord()

    Adds the CPL discord

  abstract add_logging()

    Adds the CPL internal logger

  abstract add_pipes()

    Adds the CPL internal pipes as transient

  abstract add_scoped(service_type: T, service: Optional[T] = None) → ServiceCollectionABC

    Adds a service with scoped lifetime

    Parameter:
      service_type: `Type`

        Type of the service

      service: `Callable`

        Object of the service

    Returns:

      self: `cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC`

  abstract add_singleton(service_type: T, service: Optional[T] = None) → ServiceCollectionABC

    Adds a service with singleton lifetime

    Parameter:
      service_type: `Type`

        Type of the service

      service: `Callable`

        Object of the service

    Returns:

      self: `cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC`

  abstract add_transient(service_type: T, service: Optional[T] = None) → ServiceCollectionABC

    Adds a service with transient lifetime

    Parameter:
      service_type: `Type`

        Type of the service

      service: `Callable`

        Object of the service

    Returns:

      self: `cpl_core.dependency_injection.service_collection_abc.ServiceCollectionABC`

  add_translation()

    Adds the CPL translation

  abstract build_service_provider() → ServiceProviderABC

    Creates instance of the service provider

    Returns:

      Object of type `cpl_core.dependency_injection.service_provider_abc.ServiceProviderABC`

## cpl_core.dependency_injection.service_descriptor module

class cpl_core.dependency_injection.service_descriptor.ServiceDescriptor(implementation: Optional[Union[type, object]], lifetime: ServiceLifetimeEnum, base_type=None)

  Bases: `object`

  Descriptor of a service

  Parameter:
    implementation: Union[`type`, Optional[`object`]]

      Object or type of service

    lifetime: `cpl_core.dependency_injection.service_lifetime_enum.ServiceLifetimeEnum`

      Lifetime of the service

  property base_type: type
  property implementation: Optional[Union[type, object]]
  property lifetime: ServiceLifetimeEnum
  property service_type: type

## cpl_core.dependency_injection.service_lifetime_enum module

class cpl_core.dependency_injection.service_lifetime_enum.ServiceLifetimeEnum(value)

  Bases: `Enum`

  An enumeration.

  scoped = 1
  singleton = 0
  transient = 2

## cpl_core.dependency_injection.service_provider module

class cpl_core.dependency_injection.service_provider.ServiceProvider(service_descriptors: list[ cpl_core.dependency_injection.service_descriptor.ServiceDescriptor ], config: ConfigurationABC, db_context: Optional[ DatabaseContextABC ])

  Bases: `ServiceProviderABC`

  Provider for the services

  Parameter:
    service_descriptors: list[`cpl_core.dependency_injection.service_descriptor.ServiceDescriptor`]

      Descriptor of the service

    config: `cpl_core.configuration.configuration_abc.ConfigurationABC`

      CPL Configuration

    db_context: Optional[`cpl_core.database.context.database_context_abc.DatabaseContextABC`]

      Database representation

  build_by_signature(sig: Signature) → list[T]
  build_service(service_type: type) → object

    Creates instance of given type

    Parameter:
      instance_type: `type`

        The type of the searched instance

    Returns:

      Object of the given type

  create_scope() → ScopeABC

    Creates a service scope

    Returns:

      Object of type `cpl_core.dependency_injection.scope_abc.ScopeABC`

  get_service(service_type: T) → Optional[T]

    Returns instance of given type

    Parameter:
      instance_type: `cpl_core.type.T`

        The type of the searched instance

    Returns:

      Object of type Optional[`cpl_core.type.T`]

  get_services(service_type: T) → list[Optional[T]]

    Returns instance of given type

    Parameter:
      instance_type: `cpl_core.type.T`

        The type of the searched instance

    Returns:

      Object of type list[Optional[`cpl_core.type.T`]

  set_scope(scope: ScopeABC )

    Sets the scope of service provider

    Parameter:
      Object of type `cpl_core.dependency_injection.scope_abc.ScopeABC`

        Service scope

## cpl_core.dependency_injection.service_provider_abc module

class cpl_core.dependency_injection.service_provider_abc.ServiceProviderABC

  Bases: `ABC`

  ABC for the class `cpl_core.dependency_injection.service_provider.ServiceProvider`

  abstract build_by_signature(sig: Signature) → list[T]
  abstract build_service(service_type: type) → object

    Creates instance of given type

    Parameter:
      instance_type: `type`

        The type of the searched instance

    Returns:

      Object of the given type

  abstract create_scope() → ScopeABC

    Creates a service scope

    Returns:

      Object of type `cpl_core.dependency_injection.scope_abc.ScopeABC`

  abstract get_service(instance_type: Type[T]) → Optional[T]

    Returns instance of given type

    Parameter:
      instance_type: `cpl_core.type.T`

        The type of the searched instance

    Returns:

      Object of type Optional[`cpl_core.type.T`]

  abstract get_services(service_type: T) → list[Optional[T]]

    Returns instance of given type

    Parameter:
      instance_type: `cpl_core.type.T`

        The type of the searched instance

    Returns:

      Object of type list[Optional[`cpl_core.type.T`]

  classmethod inject(f=None)

    Decorator to allow injection into static and class methods

    Parameter:

      f: Callable

    Returns:

      function

  classmethod set_global_provider(provider: ServiceProviderABC )
  abstract set_scope(scope: ScopeABC )

    Sets the scope of service provider

    Parameter:
      Object of type `cpl_core.dependency_injection.scope_abc.ScopeABC`

        Service scope

## Module contents

### cpl-core CPL core

CPL core package

copyright

  3. 2020 - 2023 sh-edraft.de

license

  MIT, see LICENSE for more details.

class cpl_core.dependency_injection.VersionInfo(major, minor, micro)

  Bases: `tuple`

  major

    Alias for field number 0

  micro

    Alias for field number 2

  minor

    Alias for field number 1