Skip to content
/ io_di Public

✨ Ultra-compact library for singleton dependency injection

License

Notifications You must be signed in to change notification settings

MyrtIO/io_di

Repository files navigation

io_di Quality Assurance

Ultra-compact library for singleton dependency injection. Allows to simplify singleton management in a small micro-controller project.

Usage

Provide

To provide the dependency, you need to create 2 files. In the .cpp (or .cc) file you create the entity to be provided, and in the .h file you represent that entity externally. The export takes place via the interface. Example:

// platform.h
#include <io_di.h>
#include "leds/leds.h"
#include "interfaces.h"

IO_PROVIDE(ILightPlatform, LightPlatform);
// platform.cpp
#include "platform.h"

IO_PROVIDE_INSTANCE(ILightPlatform, LightPlatform);

Inject

The IO_INJECT macro is used for injection. It returns a pointer to an instance of the class which implements the interface.

// clock.h
#include <io_di.h>
#include "leds/leds.h"

class ClockCapability {
private:
  ILightPlatform* leds_ = IO_INJECT(ILightPlatform);
}