Class ServiceProviderActivityExtensions
Extension methods for IServiceProvider for use by activities.
public static class ServiceProviderActivityExtensions
- Inheritance
-
ServiceProviderActivityExtensions
- Inherited Members
Methods
GetRequiredDevice<TDevice>(IServiceProvider, string?)
Gets a device from the IDeviceRegistry device registry service.
public static TDevice GetRequiredDevice<TDevice>(this IServiceProvider serviceProvider, string? name = null) where TDevice : class
Parameters
serviceProviderIServiceProvidernamestringAn optional device name.
Returns
- TDevice
The device.
Type Parameters
TDeviceThe device type.
Remarks
- If device type
TDevicehas never been registered or currently has no configured devices, InvalidOperationException will be thrown. - If
nameis null or empty, then the first registered device of typeTDevicewill be returned. - Otherwise, the first registered device of type
TDevicewith a name that matchesname(case-sensitive) will be returned, or InvalidOperationException will be thrown if a match is not found.
Any configuration changes while the application is running that cause the device list for type TDevice to be regenerated will
cause all active devices of that type to be disposed (if they implement IDisposable and recreated from the new configuration. While
configuration changes typically only happen during application startup, clients should nonetheless hold on to and use the returned reference for
only as long as is needed.
Exceptions
- InvalidOperationException
Required service of type IDeviceRegistry is not available.
- InvalidOperationException
The registered device could not be found.