Based on my previous blog post “Decouple IoC/DI container when authoring a C# library“ I have written some C# Nuget packages to have that Service Registry thing easily available in all my C# projects. The package(s) are called “Common Service Registry” (see here).
Currently the Common Service Registry (CSR) contains three packages. You mainly need two of them. The one always needed is the
CommonServiceRegistry.Core. It contains the basic interfaces like
ICommonServiceRegistry against which one needs to register its DI needs.
To finally use the Common Service Registry one also needs an adapter package that build the bridge between the concrete IoC product you are using and the Common Service Registry.
The following two adapters are currently available:
CommonServiceRegistry.SimpleInjectorfor using CSR with Simple Injector (my favorite)
CommonServiceRegistry.Unityfor using CSR with Unity
So you need the Core package and one of the above adapter. If you need an additional adapter please create an issue over on GitBub.
How to use
Check out the how to use over at GitHub. Its really easy to use that thing. The application needs one additional line and the library needs no additional lines of code (comparing to register without Common Service Registry).
Writing an adapter
A new adapter can be implemented with minimal effort. See the source-code of the other adapters (eg. this one). Note that each adapter also should have its unit-test assembly and that there is a base-class for adapter tests. So writing unit-tests for new adapters is done with a few lines of code as you can see here.
Contributions are very welcome. If you like to check out (or fork) the source-code you’ll find it on here GitHub. You can have a look at the issues and pick one to work on.
I love to write software. More then two decades ago I managed to make my hobby my full-time job so I spent more then 20 year writing professional software (I guess that makes me a "Senior Software Developer"). The last few years I spend most of the time developing in C#/.Net for all kind of windows-, web- and embedded-software.
In my free time I enjoy my family, taking photos and go diving in cold lakes and rivers in Switzerland.