QuteContainer is a lightweight Inversion of Control (IoC) container to use for Dependency Injection. QuteContainer is build with and for the C++ Qt framework. QuteContainer can automatically resolve object dependency trees using constructor parameter injection. QuteContainer is inspired by the Microsoft UnityContainer.
:::C++
class AddressBook : public IAddressBook
{
Q_OBJECT
public:
Q_INVOKABLE AddressBook(QObject *parent, IPersonRepository *personRepository,
IDataBase *dataBase);
};
AddressBook is a class with 2 dependencies: IPersonRepository and IDataBase.
QuteContainer can now resolve these dependencies automatically:
:::C++
QuteContainer quteContainer(0);
//register Interfaces which are mapped to classes
quteContainer.registerType<IAddressBook, AddressBook>(true);
quteContainer.registerType<IDataBase, DataBase>(true);
quteContainer.registerType<IPersonRepository, PersonRepository>(true);
//resolve a AddressBook class, dependent parameter will be created before.
IAddressBook *addressBook=quteContainer.resolve<IAddressBook>();
QuteContainer has created 3 objects internally: Database, PersonRepository
and AddressBook.The object tree could be even more complex. For example IPersonRepository could have other dependencies.