ServiceDescriber

class ServiceDescriber

Public Static Functions

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeSingleton(std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), serviceKey - service key passed, implementationKey - nullptr, factory - default factory using TImplementation constructor, castOffset - cast offset between TImplementation and TService in bytes,

Example:

ServiceDescriptor descriptor1 = ServiceDescriber::describeSingleton<TestClass>();
ServiceDescriptor descriptor2 = ServiceDescriber::describeSingleton<BaseClass, ImplementationClass>();

See also

Constructor requirements

Template Parameters:
  • TService – base service type

  • TImplementation – service implementation type must inherit from TService and must have one constructor

Parameters:

serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeScoped(std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - scoped, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), serviceKey - service key passed, implementationKey - nullptr, factory - default factory using TImplementation constructor, castOffset - cast offset between TImplementation and TService in bytes,

Example:

ServiceDescriptor descriptor1 = ServiceDescriber::describeScoped<TestClass>();
ServiceDescriptor descriptor2 = ServiceDescriber::describeScoped<BaseClass, ImplementationClass>();

See also

Constructor requirements

Template Parameters:
  • TService – base service type

  • TImplementation – service implementation type must inherit from TService and must have one constructor

Parameters:

serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeTransient(std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - transient, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), serviceKey - service key passed, implementationKey - nullptr, factory - default factory using TImplementation constructor, castOffset - cast offset between TImplementation and TService in bytes,

Example:

ServiceDescriptor descriptor1 = ServiceDescriber::describeTransient<TestClass>();
ServiceDescriptor descriptor2 = ServiceDescriber::describeTransient<BaseClass, ImplementationClass>();

See also

Constructor requirements

Template Parameters:
  • TService – base service type

  • TImplementation – service implementation type must inherit from TService and must have one constructor

Parameters:

serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describe(const ServiceLifeTime lifeTime, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - given lifetime, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), serviceKey - service key passed, implementationKey - nullptr, factory - default factory using TImplementation constructor, castOffset - cast offset between TImplementation and TService in bytes,

Example:

ServiceDescriptor descriptor1 = ServiceDescriber::describe<TestClass>(ServiceLifeTime::scoped());
ServiceDescriptor descriptor2 =
         ServiceDescriber::describe<BaseClass, ImplementationClass>(ServiceLifeTime::transient());

See also

Constructor requirements

Template Parameters:
  • TService – base service type

  • TImplementation – service implementation type must inherit from TService and must have one constructor

Parameters:
  • lifeTime – service life time Singleton Scoped or Transient

  • serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeSingleton(TImplementation &service, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), serviceKey - service key passed, implementationKey - nullptr, factory - factory with external service pointer, castOffset - cast offset between TImplementation and TService in bytes,

Example:

TestClass test;
ServiceDescriptor descriptor1 = ServiceDescriber::describeSingleton<TestClass>(test);

ImplementationClass implementation;
ServiceDescriptor descriptor =
             ServiceDescriber::describeSingleton<BaseClass, ImplementationClass>(implementation);

Template Parameters:
  • TService – base service type

  • TImplementation – service implementation type must inherit from TService

Parameters:
  • serviceKey – service key can be empty or nullptr to describe default service

  • service – external service pointer

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeSingleton(TImplementation *service, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), serviceKey - service key passed, implementationKey - nullptr, factory - factory with external service pointer, castOffset - cast offset between TImplementation and TService in bytes,

Example:

TestClass test;
ServiceDescriptor descriptor1 = ServiceDescriber::describeSingleton<TestClass>(&test);

ImplementationClass implementation;
ServiceDescriptor descriptor =
             ServiceDescriber::describeSingleton<BaseClass, ImplementationClass>(&implementation);

Template Parameters:
  • TService – base service type

  • TImplementation – service implementation type must inherit from TService

Parameters:
  • serviceKey – service key can be empty or nullptr to describe default service

  • service – external service pointer

template<class FactoryFcn>
static inline ServiceDescriptor describeSingletonFrom(FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeSingletonFrom(
      [](const ServiceDescriptor &) { return std::make_unique<TestClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class FactoryFcn>
static inline ServiceDescriptor describeScopedFrom(FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - scoped, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeScopedFrom(
      [](const ServiceDescriptor &) { return std::make_unique<TestClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class FactoryFcn>
static inline ServiceDescriptor describeTransientFrom(FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - transient, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeTransientFrom(
      [](const ServiceDescriptor &) { return std::make_unique<TestClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class FactoryFcn>
static inline ServiceDescriptor describeFrom(const ServiceLifeTime lifeTime, FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - given service lifetime, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeFrom(ServiceLifeTime::scoped(),
      []() { return std::make_unique<TestClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • lifeTime – service life time Singleton Scoped or Transient

  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeSingletonFrom(FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeSingletonFrom<BaseClass>(
      []() { return std::make_unique<ImplementationClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeScopedFrom(FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - scoped, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeScopedFrom<BaseClass>(
      []() { return std::make_unique<ImplementationClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeTransientFrom(FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - transient, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeTransientFrom<BaseClass>(
      []() { return std::make_unique<ImplementationClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeFrom(const ServiceLifeTime lifeTime, FactoryFcn &&factory, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - given service lifetime, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, serviceKey - service key passed, implementationKey - nullptr, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeFrom<BaseClass>(ServiceLifeTime::scoped(),
      []() { return std::make_unique<ImplementationClass>(); });

Template Parameters:

FactoryFcn – factory functor type

Parameters:
  • lifeTime – service life time Singleton Scoped or Transient

  • factory – service factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers

  • serviceKey – service key can be empty or nullptr to describe default service

template<class TAlias, class TService>
static inline ServiceDescriptor describeAlias(std::unique_ptr<std::string> serviceAliasKey = nullptr, std::unique_ptr<std::string> serviceKey = nullptr)

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TAlias), implementationTypeId - typeid(TService), serviceKey - service alias key passed, implementationKey - service key passed, factory - default factory using FactoryFcn factory functor, castOffset - cast offset between TImplementation and TService in bytes

Example:

ServiceDescriptor descriptor = ServiceDescriber::describeAlias<AliasClass, ServiceClass>();

Template Parameters:
  • TAlias – base service type - alias type

  • TService – service type must inherit from TService

Parameters:
  • serviceAliasKey – alias service key can be empty to describe default alias service

  • serviceKey – service key can be empty or nullptr to describe default service