Screenshot of a unit test that serves as example of the C++ dependency injector.
At the top, it creates a `StandardServiceCollection` and calls `AddSingleton<Interface, Implementation>()` on it to register two services. The constructor arguments of the `Implementation` classes are automatically detected via template magic.
It then calls `BuildServiceProvider()` on the `StandardServiceCollection` to produce a `ServiceProvider` instance.
From this instance, it requests one of the registered services (by its interface) and calls a method on that demonstrates that other service, which it depends on through the implementaiton class' constructor arguments, had been provided to the constructor when it was called (recursive dependency resolution).
My C++20 dependency injector rewrite is coming along.
It's loosely inspired by Microsoft.Extensions.DependencyInjection, with a ServiceCollection, .AddSingleton<Ifc,Impl>(), service scopes, automatic constructor argument detection, all done in pure C++20.
#programming #moderncpp #templates