Hypodermic IoC Container

repository·master·Indexed 20 days ago

https://github.com/ybainier/hypodermic

A non-intrusive, header-only Inversion of Control (IoC) container for C++ that manages component creation and dependency injection. It utilizes a ContainerBuilder for type registration and a resolve method to instantiate components and their dependency graphs.

Tokens
483
Snippets
2
Records
2
Agent score
20%

What's inside Hypodermic

  1. How to configure and use the Hypodermic container

    master

    The Hypodermic workflow relies on two primary classes: ContainerBuilder and the container instance returned by build().

    Registration

    Use ContainerBuilder::registerType<T>() to tell the container which types it is responsible for creating. This allows the container to understand how to instantiate T and satisfy its dependencies.

    Resolution

    Once the container is built, use the resolve<T>() method to obtain an instance of the requested type. The container will automatically handle the instantiation and dependency graph construction for T based on your registrations.

    ContainerBuilder builder;
    builder.registerType< MessageDispatcher >();
    auto container = builder.build();
    
    auto dispatcher = container->resolve< MessageDispatcher >();
  2. Get started with Hypodermic dependency injection

    master

    Hypodermic is a non-intrusive, header-only Inversion of Control (IoC) container for C++. It manages the creation and lifecycle of components and their dependencies, reducing the need for manual boilerplate code.

    To use Hypodermic, you follow a two-step process:

    1. Configure: Use a ContainerBuilder to register your component types.
    2. Resolve: Build the container and use it to request instances of the registered types.
    // 1. Configure the container by registering components
    ContainerBuilder builder;
    builder.registerType< MessageDispatcher >();
    auto container = builder.build();
    
    // 2. Resolve an instance of the type
    auto dispatcher = container->resolve< MessageDispatcher >();