net90_PropertyGridHelpers.ServiceProviders_CustomServiceProvider - dparvin/PropertyGridHelpers GitHub Wiki

CustomServiceProvider class

A lightweight implementation of IServiceProvider that allows manual registration and retrieval of service instances by type.

public class CustomServiceProvider : IServiceProvider

Public Members

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.

Remarks

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.

Examples

var provider = new CustomServiceProvider();
provider.AddService(typeof(IMyService), new MyService());
var service = provider.GetService(typeof(IMyService)) as IMyService;

See Also

⚠️ **GitHub.com Fallback** ⚠️