-
Notifications
You must be signed in to change notification settings - Fork 11
injeqt::module::add_type
Rafał Malinowski edited this page Oct 19, 2016
·
3 revisions
injeqt::module::add_type
adds a type to injector that will be instantiated using default constructor.
add_type<T>();
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.
class Configuration : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE explicit Configuration();
};
class ConfigurationModule : public injeqt::module
{
public:
ConfigurationModule()
{
add_type<Configuration>();
}
};
-
T
must be derived fromQObject
(directly or indirectly) -
T
must useQ_OBJECT
macro -
T
must have a default constructor marked withQ_INVOKABLE
- call to
add_type<T>()
must be present in exactly one module of injector
-
qobject_type
whenT
isQObject
, not derived from it -
default_constructor_not_found
when T does not have default constructor marked withQ_INVOKABLE
- when object of type
T
is requested, injector instantiates it using default constructor and ensures that all dependencies ofT
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 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