// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT License.
// See the LICENSE file in the project root for more information.
using System.ComponentModel;
namespace System.Reactive.PlatformServices
{
///
/// (Infrastructure) Interface for enlightenment providers.
///
///
/// This type is used by the Rx infrastructure and not meant for public consumption or implementation.
/// No guarantees are made about forward compatibility of the type's functionality and its usage.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public interface IPlatformEnlightenmentProvider
{
///
/// (Infrastructure) Tries to gets the specified service.
///
/// Service type.
/// Optional set of arguments.
/// Service instance or null if not found.
T? GetService(params object[] args) where T : class;
}
///
/// (Infrastructure) Provider for platform-specific framework enlightenments.
///
///
/// This type is used by the Rx infrastructure and not meant for public consumption or implementation.
///
[EditorBrowsable(EditorBrowsableState.Never)]
public static class PlatformEnlightenmentProvider
{
private static IPlatformEnlightenmentProvider _current = CreatePlatformProvider();
//
// NOTE TO MAINTAINERS
//
// Do *NOT* remove this mechanism which has been used beyond its original goal of supporting dependency injection when we were unifying
// the different Rx implementations as one Portable Library with platform-specific PlatformServices assemblies on top. Besides this, it
// has been used (and is still being used) for hosting scenarios where the host wants control over thread creation (cf. CAL), or other
// services (e.g. interception of query operators for logging, debugging, quota management, policy injection, etc.). Compat matters and
// lack thereof results in users getting stuck on older versions or having to resort to forking.
//
///
/// (Infrastructure) Gets the current enlightenment provider. If none is loaded yet, accessing this property triggers provider resolution.
///
///
/// This member is used by the Rx infrastructure and not meant for public consumption or implementation.
///
public static IPlatformEnlightenmentProvider Current
{
get => _current;
set => _current = value ?? throw new ArgumentNullException(nameof(value));
}
private static IPlatformEnlightenmentProvider CreatePlatformProvider() => new CurrentPlatformEnlightenmentProvider();
}
}