Code Monkey home page Code Monkey logo

kangaru's Introduction

kangaru Build status Build Status BCH compliance Join the chat at https://gitter.im/gracicot/kangaru Try online

Kangaru is an inversion of control container for C++11 and later. It supports features like operation between containers, injection via function parameter, automatic call of member functions on instance creation and much more!

Our goal is to create a DI container capable of automatic, recusive dependency injection. We also want to do most diagnostics at compile time, while keeping the simplest interface possible. On top of that, we don't want to be intrusive into user/library code.

Kangaru is a header only library because of it's extensive use of templates. The name kangaru comes from the container's feature to inject itself into a service as a dependency, and because kangaroos are awesome.


Documentation and tutorial is in the wiki and the doc folder!

Looking for the latest stable version? Check out our release page.

Here's a quick demo to show usage of this library:

#include <kangaru/kangaru.hpp>
#include <iostream>

// Normal classes with dependency between them
struct Camera {};

struct Scene {
    Camera& camera;
};

// This is the configuration of our classes.
// Structure and dependency graph is defined here.

// Camera is a single service so the service has a shared instance.
// It will be injected and returned as a reference.
struct CameraService : kgr::single_service<Camera> {};

// Scene is not single, so the container return scenes by value.
// Also, we depends on a camera to be constructed.
struct SceneService : kgr::service<Scene, kgr::dependency<CameraService>> {};

int main()
{
    kgr::container container;
    
    // The service function return instances of the normal classes.
    Scene scene = container.service<SceneService>();
    Camera& camera = container.service<CameraService>();
    
    std::cout
        << std::boolalpha
        << (&scene.camera == &camera) << std::endl; // outputs true
}

Try this example online too see how it runs.

Features

  • Recursive dependency resolution
  • Non intrusive. No existing classes need modification.
  • You tell the container how to construct your types
  • You tell the container how to store them
  • You tell the container how they are injected
  • Injection by setters
  • Function parameter injection
  • Clean and simple API
  • Low runtime overhead
  • Header only library
  • Clean diagnostics at compile-time.

Installation

To make kangaru available on your machine, you must clone the repository and create a build directory:

$ git clone https://github.com/gracicot/kangaru.git && cd kangaru
$ mkdir build && cd build

Then use cmake to generate the makefile and export the package informations:

$ cmake ..

That's it! Link it to your project using cmake and you can already include and code!

Optionally, you can also install kangaru on your system:

# make install

Adding Include Path

You must use the find_package function:

find_package(kangaru REQUIRED)

And then add the include dirs to your target:

target_link_libraries(<YOUR TARGET> PUBLIC kangaru)

Then you can include the library as follow:

#include <kangaru/kangaru.hpp>

What's next?

There is some feature I would like to see become real. Here's a list of those, feel free to contribute!

  • Tests for compile-time errors
  • More test coverage
  • Better messages for compile-time errors (ongoing)
  • Service sources, more detail here: #41

Got suggestions or questions? Discovered a bug? Please open an issue and we'll gladly respond!

Contributing

To contribute, simply open a pull request or an issue and we'll discuss together about how to make this library even more awesome!

Want to help? Pick an issue on our issue tracker!

Who's using kangaru?

Here's a list of projets making use of kangaru

  • <to be filled>

Using kangaru?

Let me know of your projects that uses kangaru! I'll be glad to fill the list above with your project's name.

kangaru's People

Contributors

gracicot avatar denisss025 avatar d1amond avatar lracicot avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.