C++ TargetRTS
|
Dependency injector for RT applications. More...
#include <RTInjector.h>
Public Member Functions | |
void | registerCreateFunction (const std::string &id, std::function< RTActor *(RTController *, RTActorRef *, int)> createFunc) |
Register a create function to be used for incarnating capsule instances in a capsule part. | |
std::function< RTActor *(RTController *, RTActorRef *, int)> | getCreateFunction (const std::string &id) |
Get a create function registered for incarnating capsule instances in a capsule part. | |
RTActor * | create (RTController *rts, RTActorRef *ref, int index) |
Create a capsule instance. | |
RTInjector (RTInjector const &)=delete | |
void | operator= (RTInjector const &)=delete |
Static Public Member Functions | |
static RTInjector & | getInstance () |
Access the singleton injector instance (created on first access) | |
Dependency injector for RT applications.
At runtime a capsule instance depends on other capsule instances. Instead of hard coding such dependencies inside the capsule itself, the dependency injector approach allows to register such dependencies in a centralized location. Thereby you can configure the application by changing in that single place only.
A typical usage of this class is to access the singleton instance at application start-up (for example in the constructor of the top capsule). There you then configure the dependencies to be injected by registering create functions for capsule parts that you want to incarnate in a non-default way. Some example of customization possibilities (implemented by the create function):
Dependencies are usually not changed once registered, but if needed it's possible to do so (the implementation is thread safe).
RTActor * RTInjector::create | ( | RTController * | rts, |
RTActorRef * | ref, | ||
int | index | ||
) |
Create a capsule instance.
If a create function has been registered for the specified capsule part it will be used for creating the capsule instance. Otherwise nullptr will be returned, to allow the capsule instance to be created as default (if possible).
rts | Default controller thread to run the created capsule instance (a registered create function may override this) |
ref | Capsule part to host the created capsule instance |
index | Index where to insert the created capsule instance in the capsule part |
std::function< RTActor *(RTController *, RTActorRef *, int)> RTInjector::getCreateFunction | ( | const std::string & | id | ) |
Get a create function registered for incarnating capsule instances in a capsule part.
id | Qualified id string for the capsule part (e.g. "/part1:0/part2") |
|
static |
Access the singleton injector instance (created on first access)
void RTInjector::registerCreateFunction | ( | const std::string & | id, |
std::function< RTActor *(RTController *, RTActorRef *, int)> | createFunc | ||
) |
Register a create function to be used for incarnating capsule instances in a capsule part.
id | Qualified id string for the capsule part (e.g. "/part1:0/part2") |
createFunc | Create function to register |