using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
namespace DigitalData.Core.Abstractions;
///
/// Extension methods for to retrieve configuration options.
///
public static class ServiceProviderExtensions
{
///
/// Retrieves an instance of from the .
/// If the options are not registered, returns null.
///
/// The type of the options to retrieve.
/// The service provider instance.
/// An instance of or null if not found.
public static TOptions? GetOptions(this IServiceProvider service) where TOptions : class
=> service.GetService>()?.Value;
///
/// Retrieves an instance of from the .
/// Throws an exception if the options are not registered.
///
/// The type of the options to retrieve.
/// The service provider instance.
/// An instance of .
/// Thrown when the options are not registered.
public static TOptions GetRequiredOptions(this IServiceProvider service) where TOptions : class
=> service.GetRequiredService>().Value;
}