4 ms·
Non Intrusive Static Recursive Dependency Injection for C++14
- matt42 12y agoThe source code is here, interesting if you enjoy c++14 meta programming: https://github.com/matt-42/iod/blob/master/iod/di.hh https://github.com/matt-42/iod/blob/master/iod/di.hh
- deleted 12y ago[deleted]
- _yosefk 12y agoIOD comes with example code using identifiers such as _Name. AFAIK all C and C++ standards reserve all identifiers starting with _[A-Z] as well as those starting with __ for compiler use (and I've seen people complain about it a couple of times - about a decade ago someone was hit by a new gcc version #defining _Y, and recently someone else got hit by a more recent gcc version #defining _X, on some platforms but not others...) So I think a different convention (Name_, _name, etc.) would be better to use in example code, so that people don't learn a convention that might byte them down the road.
- matt42 12y agoThanks. I was not aware of this rule. I will change this convention as soon as possible. It is a bit strange that g++ did not report any warning...
- cheez 12y agoMy favourite topic! I am glad that people are still thinking about automated DI in C++. I am sure the new standards make a lot of things easier. This library looks like a cool experiment and I hope the author continues to move in this direction. Here is my version: http://bitbucket.org/cheez/dicpp http://bitbucket.org/cheez/dicpp With the following caveats: * It is not very cool * It works really well for my uses * It is not as efficient as the compile-time ones WRT efficiency, 99% of DI is done at application startup and you can easily make that efficient enough by delaying instantiations until you actually need them. The bottleneck at startup so far has never been the library itself. I continue to look for one that allows me to create compiler firewalls so I can use it instead of my own. Alternatively, if someone wants to give me tips to avoid the hideous DI_CONSTRUCTOR (see https://bitbucket.org/cheez/dicpp/src/HEAD/lib/examples/stockquote/StockQuoteApp.hpp#cl-15 https://bitbucket.org/cheez/dicpp/src/HEAD/lib/examples/stoc...) I'm all ears. There was one posted on the Boost list not so long ago which was VERY promising but I haven't managed to get around to using it yet.
- amelius 12y agoWhat baffles me is this: Why does such a (conceptually) simple thing require such a hairy implementation?
- cheez 12y agoC++
- TillE 12y agoIs it conceptually simple? The examples demonstrate behavior that would be pretty impressive even in a dynamic language. Obviously the trivial form of dependency injection (just pass a parameter manually) requires no special library.
- matt42 12y agoI am not aware of simpler DI implementations running during the compilation. But I agree that C++ meta programming is often hard to read...
- malisper 12y agoCan someone explain what exactly the library does? All I got from the description is something about a way of building an argument list, and then how it is possible to fulfill some dependencies with factories or make methods or something.
- matt42 12y agoIn the description the arguments of the function are its dependencies, and factories are called via their make method (which can also have arguments/dependencies).
- matt42 12y agoYou can have a look at the Go implementation: https://github.com/facebookgo/inject/blob/master/inject.go https://github.com/facebookgo/inject/blob/master/inject.go