net90_PropertyGridHelpers.ServiceProviders_CustomServiceProvider - dparvin/PropertyGridHelpers GitHub Wiki
A lightweight implementation of IServiceProvider that allows manual registration and retrieval of service instances by type.
public class CustomServiceProvider : IServiceProvider
name | description |
---|---|
CustomServiceProvider() | The default constructor. |
AddService(…) | Registers a service instance with the specified service type. |
GetService(…) | Retrieves a service object of the specified type. |
This class is useful in testing scenarios or situations where full-fledged dependency injection is unnecessary. It is also used internally by the PropertyGridHelpers
library to support dynamic or programmatic access to services that would otherwise be resolved via attributes.
var provider = new CustomServiceProvider();
provider.AddService(typeof(IMyService), new MyService());
var service = provider.GetService(typeof(IMyService)) as IMyService;
- namespace PropertyGridHelpers.ServiceProviders
- assembly PropertyGridHelpers
- CustomServiceProvider.cs