ServiceDescriber#

class ServiceDescriber#

Public Static Functions

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeSingleton()#

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), factory - default factory using TImplementation constructor

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

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeScoped()#

Creates service descriptor.

Creates service descriptor with: lifetime - scoped, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), factory - default factory using TImplementation constructor

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

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeTransient()#

Creates service descriptor.

Creates service descriptor with: lifetime - transient, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), factory - default factory using TImplementation constructor

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

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describe(const ServiceLifeTime lifetime)#

Creates service descriptor.

Creates service descriptor with: lifetime - given lifetime, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), factory - default factory using TImplementation constructor

Example:

ServiceDescriptor descriptor1 = ServiceDescriber::describe<TestClass>(ServiceLifeTimes::Scoped);
ServiceDescriptor descriptor2 =
         ServiceDescriber::describe<BaseClass, ImplementationClass>(ServiceLifeTimes::Transient);

See also

Constructor requirements

Template Parameters:
  • TService – base service type

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

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeSingleton(TImplementation &service)#

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), factory - factory with external service pointer

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

template<class TService, class TImplementation = TService>
static inline ServiceDescriptor describeSingleton(TImplementation *service)#

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - typeid(TImplementation), factory - factory with external service pointer

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

template<class FactoryFcn>
static inline ServiceDescriptor describeSingletonFrom(FactoryFcn &&factory)#

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:

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

template<class FactoryFcn>
static inline ServiceDescriptor describeScopedFrom(FactoryFcn &&factory)#

Creates service descriptor.

Creates service descriptor with: lifetime - scoped, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:

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

template<class FactoryFcn>
static inline ServiceDescriptor describeTransientFrom(FactoryFcn &&factory)#

Creates service descriptor.

Creates service descriptor with: lifetime - transient, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:

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

template<class FactoryFcn>
static inline ServiceDescriptor describeFrom(const ServiceLifeTime lifetime, FactoryFcn &&factoryFcn)#

Creates service descriptor.

Creates service descriptor with: lifetime - given service lifetime, serviceTypeId - extracted from factory return type, implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:

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

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeSingletonFrom(FactoryFcn &&factory)#

Creates service descriptor.

Creates service descriptor with: lifetime - singleton, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:
  • TService – base service type

  • FactoryFcn – is factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers, implementation type must inherit from TService

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeScopedFrom(FactoryFcn &&factory)#

Creates service descriptor.

Creates service descriptor with: lifetime - scoped, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:
  • TService – base service type

  • FactoryFcn – is factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers, implementation type must inherit from TService

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeTransientFrom(FactoryFcn &&factory)#

Creates service descriptor.

Creates service descriptor with: lifetime - transient, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:
  • TService – base service type

  • FactoryFcn – is factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers, implementation type must inherit from TService

template<class TService, class FactoryFcn>
static inline ServiceDescriptor describeFrom(const ServiceLifeTime lifetime, FactoryFcn &&factoryFcn)#

Creates service descriptor.

Creates service descriptor with: lifetime - given service lifetime, serviceTypeId - typeid(TService), implementationTypeId - extracted from factory return type, factory - default factory using FactoryFcn factory functor

Example:

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

Template Parameters:
  • TService – base service type

  • FactoryFcn – is factory functor with this scheme: (Services…) -> std::unique_ptr<TImplementation> | TImplementation, where services are pointers, unique pointers, references, vectors with pointers or unique pointers, implementation type must inherit from TService

template<class TAlias, class TService>
static inline ServiceDescriptor describeAlias()#

Creates service descriptor.

Creates service descriptor with: lifetime - scoped, serviceTypeId - typeid(TAlias), implementationTypeId - typeid(TService), factory - nullptr

Example:

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

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

  • TService – service type must inherit from TService