LightInject
LightInject copied to clipboard
public GetAvailableServices
I'm trying to implement a Newtonsoft.DefaultContractResolver similar to this https://www.newtonsoft.com/json/help/html/DeserializeWithDependencyInjection.htm
To resolve a type <ServiceType>, I need to know if that type is registered with the container, and if so, what the ImplementingType is (Also I'd like to be able to know what the lifetime is as well).
But the method ServiceContainer.GetAvailableServices is private, and I can't figure out a way to get them. I see that GetAvailableServices has side effects -- it possibly Adds to the available services if not found.
Maybe a public method added to the interface GetRegisteredServices(Type serviceType) implemented like this?
public IEnumerable<KeyValuePair<string, ServiceRegistration>> GetRegisteredServices(Type serviceType) {
return availableServices.ContainsKey(serviceType) ? availableServices[serviceType] : null;
}
Happy to contribute a pull request if you think it's worthwhile, or consider why it's a mistake.