I'm using MVVM Cross in a project that uses multiple services. What I would like to do is to retrieve, from the IoC container a list of currently registered services. For example:
Mvx.LazyConstructAndRegisterSingleton<IService1, IService1>();
Mvx.LazyConstructAndRegisterSingleton<IService2, IService2>();
Mvx.LazyConstructAndRegisterSingleton<IService3, IService3>();
Then
var s1 = Mvx.Resolve<IService1>();
var s3 = Mvx.Resolve<IService3>();
So now I want to return a list of active services. I know that I can do this using reflection, but I wanted to know if there was a way to get this from the IoC container instead; something like:
var activeSvc = Mvx.GetAllServices();
Is this possible? In MvxSimpleIoCContainer
there is a dictionary of resolvers:
private readonly Dictionary<Type, IResolver> _resolvers = new Dictionary<Type, IResolver>();
This looks to be what I want, but it isn't publicly exposed.
No - this functionality isn't currently supported by the interface (https://github.com/MvvmCross/MvvmCross/blob/3.2/CrossCore/Cirrious.CrossCore/IoC/IMvxIoCProvider.cs) or the "simple" implementation (https://github.com/MvvmCross/MvvmCross/blob/3.2/CrossCore/Cirrious.CrossCore/IoC/MvxSimpleIoCContainer.cs)
If you feel this is functionality that would be commonly needed, then you could send a feature request (or pull request!)
But it might be easiest to start by implementing your own IoC container (based on that source) that exposes the exact functionality your platform needs.
Alternatively, you could use some reflection within your own assemblies to identify the exact services/interfaces you are looking for (it feels like your app won't actually want the list of all Types registered with IoC, but rather just a specific set that live somewhere in one particular part of your app)