Giter Site home page Giter Site logo

boost-ext / di Goto Github PK

View Code? Open in Web Editor NEW
1.1K 69.0 138.0 73.27 MB

C++14 Dependency Injection Library

Home Page: https://boost-ext.github.io/di

C++ 83.40% CMake 0.93% Makefile 0.68% Java 8.86% C# 3.95% Shell 0.73% Python 0.73% Meson 0.73%
dependency-injection metaprogramming design-patterns

di's People

Contributors

abelfodil avatar alexey-bogomolov avatar archiesw avatar dvetutnev avatar gjasny avatar jaakristioja avatar jamespharvey20 avatar kanstantsin-chernik avatar kris-jusiak avatar krzysztof-jusiak avatar legalizeadulthood avatar m-gaj avatar mlimber avatar mstaz avatar nevalsar avatar nine avatar pck avatar stevefan1999-personal avatar tphnicholas avatar tralamazza avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

di's Issues

Named with shared_ptr

QDEPS_CTOR(Test, Named< shared_ptr, Name >)
QDEPS_CTOR(Test, Named< const shared_ptr&, Name >)
QDEPS_CTOR(Test, Named< const shared_ptr&, Name >) -> Bind<int, int_<42> >::InName

Injector.install

Injector<> injector;

injector.install(m1, m2, ...); -> Injector<M1, M2, ...>

policy: binding_correctness

Bind::in_calll

C1(double) { } //error C1 doesn't have int parameter
Compilation error requested

bidnes::correctness -> the same binding in different scopes
externals with scopes

One line binding with InCall and InName -> Apply CallStack and Name

Singleton < C >::InCall < C1, C2 >
Singleton < C >::InName < Name >
Singleton < C >::InCall < C1, C2 >::InName < Name >
Singleton < C >::InName < Name >::InCall < C1, C2 >

PerRequest < C >::InCall < C1, C2 >
PerRequest < C >::InName < Name >
PerRequest < C >::InCall < C1, C2 >::InName < Name >
PerRequest < C >::InName < Name >::InCall < C1, C2 >

session scope

//todo smart ptr instead of naked ptr

struct session
{
    template<typename T>
    struct scope
    {
         scope()
              : instance_(nullptr)
         { }

         ~scope() {
             delete instance_;
         }

         void call(const entry&)
         {
              in_scope_ = true;
         }

         void call(const exit&)
         {
              in_scope_ = false;

              delete instance_;
         }

          template<typename... Args>
          T* create(Args&& args)
          {
               if (in_scope_) {
                    return new T(args...);
               }
               return nullptr;
          }
    };
};

session<
    c1
>

injector.call<Session>(entry());
injector.create<c1>();
injector.call<Session>(exit());

factory support

class c
{
CTOR(i*) {
}
};

class c1
{
CTOR(i*) {
}
};

di<
bind::in_call::to(42)
Factory,
, bind::in_call

injector;

factory
{
CTOR(int i) {
}

i* create(di& di) {
    switch(i) {
        return di.create<Impl1>();
    }

    return nullptr;
}

};

or

typedef id2type::bind<
E1, Impl1
E2, Impl2

factory_type;

create < Type > - only shared_ptr, lvalue, ptr have sens

C c = create < shared_ptr >()
C c = create < C >()
const C& c = create < C >()
C* c = create < C* >()
const C* c = create <const C* >()

const C& c = create < const C& >() //error
const C& c = create < C& >() //error
const C& c = create < shared_ptr& >() //error

Externals with base front end

Module <
Externals <
Annotate::With,
Annotate<Bind::InName::InCall >::With

Injector injector(Module(Set(42), Set(87)));

scope deduction support

class impl : i {};
class c1 {CTOR(shared_ptr);};
class c2 {CTOR(unique_ptr);};

generic_module.create();//singleton
generic_module.create();//per_request

setter injection support

class c
{
c()
: i_(0)
{ }

 void BOOST_DI_SETTER(int i) {
     i_ = i;
  }

private:
int i_;
};

di::injector<>.create();

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.