Class IServiceProviderActivityExtensions
Extension methods for IServiceProvider for use by activities.
public static class IServiceProviderActivityExtensions
- Inheritance
-
IServiceProviderActivityExtensions
- 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
serviceProvider
IServiceProviderThe service provider.
name
stringAn optional device name.
Returns
- TDevice
The device.
Type Parameters
TDevice
The device type.
Remarks
- If device type
TDevice
has never been registered or currently has no configured devices, InvalidOperationException will be thrown. - If
name
is null or empty, then the first registered device of typeTDevice
will be returned. - Otherwise, the first registered device of type
TDevice
with 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
- ArgumentNullException
serviceProvider
is null.- InvalidOperationException
Required service of type IDeviceRegistry is not available.
- InvalidOperationException
The registered device could not be found.