boost-ext / di Goto Github PK
View Code? Open in Web Editor NEWC++14 Dependency Injection Library
Home Page: https://boost-ext.github.io/di
C++14 Dependency Injection Library
Home Page: https://boost-ext.github.io/di
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< Moudle1, Policy< AllowA, AllowB > > inj1;
Injector<Policy< AllowC >, Module1 > inj2;
per_request<int, int_<32> >
class Test
{
QDEPS_CTOR(void (*f1)(int), boost::function f2, int a1[], int (&a2)[10])
{ }
};
Injector<> injector;
injector.install(m1, m2, ...); -> Injector<M1, M2, ...>
Module1<
PerRequest<int, int_<0> >
{ };
Module2<
PerRequest<int, int_<1>
{ };
Injector<Module1, Module2> injector; //error -> ambiguous int
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
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 >
config.hpp
//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());
Sngletons<
Externals //compile error
QDEPS_CTOR(i&) -> non_const_ref
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;
QDEPS_CTOR(Test, Provider i)
{
};
support of Bind<I, Provider >
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
Module <
C1, //works fine
Bind::InName //doesn't work
disallow circular dependencies
Injector injector;
Injector.visit(DotVisitor());
C1 --- C2
|
int
... in graphviz dot
?
Module <
Singleton
{ };
QDPES_CTOR(A1, S); //error -> passed by value
QDPES_CTOR(A2, shared_ptr);
OK:
External
C1(const D&)
C2(D&)
C3(shared_ptr)
Module <
Externals <
Annotate::With,
Annotate<Bind::InName::InCall >::With
Injector injector(Module(Set(42), Set(87)));
QDEPS_CTOR(Test, const I&); //lack of owner
Utility::Injector
<
BOOST_TYPEOF(fusionModule)
>
injector;//ok
Utility::Injector
<
BOOST_TYPEOF(fusionModule)
>
injector(fusionModule);//error
template<>
ConstructorTraits<C1, int, doouble>
{ };
QDEPS_CTOR(Named<If, Name>)
Bind::InName
BInd::To(32)
class impl : i {};
class c1 {CTOR(shared_ptr);};
class c2 {CTOR(unique_ptr);};
generic_module.create();//singleton
generic_module.create();//per_request
Injector<M1, M2, M3>
modules tests
class c
{
c()
: i_(0)
{ }
void BOOST_DI_SETTER(int i) {
i_ = i;
}
private:
int i_;
};
di::injector<>.create();
Annotate< Bind::InCall >::With
Module(
Set(32)
)
class C
{
public:
shared_ptr create()
{
return make_shared();
}
};
Module <
Bind ::InMethod<&C::create>
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.