Skip to content

injeqt::module::add_type

Rafał Malinowski edited this page Oct 19, 2016 · 3 revisions

Description

injeqt::module::add_type adds a type to injector that will be instantiated using default constructor.

Syntax

add_type<T>();

Call site

add_type is typically only called from constructors of types inheriting from injeqt::module. Calls to add_type made after module is passed to injeqt::injector constructor are meaningless and have no effect.

Example

class Configuration : public QObject
{
    Q_OBJECT
public:
    Q_INVOKABLE explicit Configuration();
};

class ConfigurationModule : public injeqt::module
{
public:
    ConfigurationModule()
    {
        add_type<Configuration>();
    }
};

Requirements

  • T must be derived from QObject (directly or indirectly)
  • T must use Q_OBJECT macro
  • T must have a default constructor marked with Q_INVOKABLE
  • call to add_type<T>() must be present in exactly one module of injector

Throws

  • qobject_type when T is QObject, not derived from it
  • default_constructor_not_found when T does not have default constructor marked with Q_INVOKABLE

Object initialization

  • when object of type T is requested, injector instantiates it using default constructor and ensures that all dependencies of T are also instantiated
  • all INJEQT_SET methods are called for each dependency of T with valid objects (with unspecified order)
  • all INJEQT_INIT methods of T are called (with unspecified order)

Object destruction

  • object is only destructed if it was created before
  • when injector object is about to be destructed, all INJEQT_DONE methods of T are called (with unspecified order)
  • object is destructed
Clone this wiki locally