I am looking for the input from developers who had some experience with IoC frameworks like Castle (in .NET) or in Java.
However, I am looking for something similar implemented using C++. That excludes COM, for reasons I can explain later. Is there a way to implement a pattern like a Factory, Abstract Factory or Service Provider in C++, mostly, but not exclusively on Windows platform?
Specifically, IoC should allow for an unknown number of implementations of interface(s) that can be discovered and loaded by the client app at runtime.
As the answer I am hoping for either:
- a link to the specific commercial or open source C++ IoC implementation, or
- personal experiences trying to implement it, with the list of a few major gotchas, if any.
Due to unexpected downvotes I have to add some additional specifications (which may have not been clear from the OP):
It is Ok if implementation requires a closed system, where all the components are required to link to the same version of C++ runtime library. This is not great, but is acceptable. I have been working for decade on software that installed the required version of C++ runtime, as the part of client application software installation. IOW, this is an issue for broad compatibility, but not the answer to the question that I am asking here.
I am mentioning unique_ptr because it is a C++ standard. Custom smart pointer would be Ok too. I expect that unique_ptr is probably better explored by now.
I am not asking for a draft code on how to use custom deleter with unique_ptr. Much less for a code that doesn't even compile. This is the answer that got all the upvotes. Sadly, after I commented like "this is like a blind trying to lead a deaf", the rage to punish me as the alleged offender, and to support the alleged victim, got blown out of proportions and resulted in irrational downvotes and upvotes. I am truly saddened that on a site like SO such a thing can derail purely technical problem and turn it into personal rants about politeness. It would be more polite to abstain from throwing clueless code drafts at the questions that clearly ask for actual implementation experiences. (a)
After not getting any sensible answer or a good link, I spent quite some time trying to create a sample implementation myself. I tried it in both Release and Debug builds under MSVC 2010 and it worked as I expected. That is the answer which I didn't vote as accepted, since it is my answer to my own question. I still hope for a good comments from people who are actually experienced in these issues. This answer has 2 downvotes, even if the code does what it says it does, if you actually try to compile and run it.
(a) link to the meaning of the offensive, impolite and rude phrase that caused righteous indignation, according to McGraw-Hill Dictionary of American Idioms and Phrasal Verbs and Cambridge Idioms Dictionary: