Minimal Dependency Injection Framework for C++
Single file library for implementing the dependency injection pattern
dip.hpp File Reference

Minimal dependency injection framework. More...

#include <memory>
#include <type_traits>
#include <cassert>
#include <functional>
#include <vector>

Go to the source code of this file.

Classes

struct  dip::Injector< Service >
 Custom injector. More...
 
struct  dip::instance< Service >
 Injected instance of a service. More...
 
struct  dip::instance_set< Service >
 Set of injected instances of a service. More...
 

Namespaces

namespace  dip
 Dependency injection pattern.
 

Functions

template<class Service >
void dip::inject (const Injector< Service > &injector)
 Inject a service provider using a custom injector. More...
 
template<class Service , class Provider , typename... _Args>
void dip::inject_transient (_Args &&...args)
 Inject a transient instance to a Service. More...
 
template<class Service , class Provider , typename... _Args>
void dip::inject_singleton (_Args &&...args)
 Inject a singleton instance to a Service. More...
 
template<class Service , class Provider , typename... _Args>
void dip::inject_thread_singleton (_Args &&...args)
 Inject a per-thread singleton instance to a Service. More...
 
template<class Service >
void dip::add (const Injector< Service > &injector)
 Inject a service provider using a custom injector. More...
 
template<class Service , class Provider , typename... _Args>
void dip::add_transient (_Args &&...args)
 Inject a transient instance to a Service. More...
 
template<class Service , class Provider , typename... _Args>
void dip::add_singleton (_Args &&...args)
 Inject a singleton instance to a Service. More...
 
template<class Service , class Provider , typename... _Args>
void dip::add_thread_singleton (_Args &&...args)
 Inject a per-thread singleton instance to a Service. More...
 

Detailed Description

Minimal dependency injection framework.

Author
Ángel Fernández Pineda. Madrid. Spain.
Date
2025-11-09