浏览代码

Restore PlatformEnlightenmentProvider.Current until a better service injection can be introduced

Oren Novotny 9 年之前
父节点
当前提交
3604b236e8

+ 2 - 0
Rx.NET/Source/System.Reactive.Core/Reactive/Concurrency/ConcurrencyAbstractionLayer.cs

@@ -19,7 +19,9 @@ namespace System.Reactive.Concurrency
 
         private static IConcurrencyAbstractionLayer Initialize()
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             return PlatformEnlightenmentProvider.Current.GetService<IConcurrencyAbstractionLayer>() ?? new DefaultConcurrencyAbstractionLayer();
+#pragma warning restore CS0618 // Type or member is obsolete
         }
     }
 

+ 2 - 0
Rx.NET/Source/System.Reactive.Core/Reactive/Concurrency/Scheduler.cs

@@ -138,7 +138,9 @@ namespace System.Reactive.Concurrency
 
         private static IScheduler Initialize(string name)
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             var res = PlatformEnlightenmentProvider.Current.GetService<IScheduler>(name);
+#pragma warning restore CS0618 // Type or member is obsolete
             if (res == null)
                 throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Strings_Core.CANT_OBTAIN_SCHEDULER, name));
             return res;

+ 2 - 0
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/ExceptionServices.cs

@@ -24,7 +24,9 @@ namespace System.Reactive
 
         private static IExceptionServices Initialize()
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             return PlatformEnlightenmentProvider.Current.GetService<IExceptionServices>() ?? new DefaultExceptionServices();
+#pragma warning restore CS0618 // Type or member is obsolete
         }
     }
 }

+ 2 - 0
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/HostLifecycleService.cs

@@ -76,7 +76,9 @@ namespace System.Reactive.PlatformServices
 
         private static IHostLifecycleNotifications InitializeNotifications()
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             return PlatformEnlightenmentProvider.Current.GetService<IHostLifecycleNotifications>();
+#pragma warning restore CS0618 // Type or member is obsolete
         }
     }
 

+ 7 - 1
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/PlatformEnlightenmentProvider.cs

@@ -35,7 +35,7 @@ namespace System.Reactive.PlatformServices
     [EditorBrowsable(EditorBrowsableState.Never)]
     public static class PlatformEnlightenmentProvider
     {
-        private static readonly IPlatformEnlightenmentProvider s_current = CreatePlatformProvider();
+        private static IPlatformEnlightenmentProvider s_current = CreatePlatformProvider();
 
         /// <summary>
         /// (Infrastructure) Gets the current enlightenment provider. If none is loaded yet, accessing this property triggers provider resolution.
@@ -43,12 +43,18 @@ namespace System.Reactive.PlatformServices
         /// <remarks>
         /// This member is used by the Rx infrastructure and not meant for public consumption or implementation.
         /// </remarks>
+        [Obsolete("This mechanism will be removed in the next major version", false)]
         public static IPlatformEnlightenmentProvider Current
         {
             get
             {
                 return s_current;
             }
+            set
+            {
+                if (value == null) throw new ArgumentNullException(nameof(value));
+                s_current = value;
+            }
             
         }
 

+ 4 - 0
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/SystemClock.cs

@@ -85,12 +85,16 @@ namespace System.Reactive.PlatformServices
 
         private static ISystemClock InitializeSystemClock()
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             return PlatformEnlightenmentProvider.Current.GetService<ISystemClock>() ?? new DefaultSystemClock();
+#pragma warning restore CS0618 // Type or member is obsolete
         }
 
         private static INotifySystemClockChanged InitializeSystemClockChanged()
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             return PlatformEnlightenmentProvider.Current.GetService<INotifySystemClockChanged>() ?? new DefaultSystemClockMonitor();
+#pragma warning restore CS0618 // Type or member is obsolete
         }
 
         internal static void Register(LocalScheduler scheduler)

+ 2 - 0
Rx.NET/Source/System.Reactive.Core/Reactive/Internal/TaskServices.cs

@@ -17,7 +17,9 @@ namespace System.Reactive
 
         private static ITaskServices Initialize()
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             return PlatformEnlightenmentProvider.Current.GetService<ITaskServices>() ?? new DefaultTaskServices();
+#pragma warning restore CS0618 // Type or member is obsolete
         }
 
         public static bool TrySetCanceled<T>(this TaskCompletionSource<T> tcs, CancellationToken token)

+ 2 - 0
Rx.NET/Source/System.Reactive.Linq/Reactive/Internal/QueryServices.cs

@@ -18,7 +18,9 @@ namespace System.Reactive.Linq
 
         private static IQueryServices Initialize()
         {
+#pragma warning disable CS0618 // Type or member is obsolete
             return PlatformEnlightenmentProvider.Current.GetService<IQueryServices>() ?? new DefaultQueryServices();
+#pragma warning restore CS0618 // Type or member is obsolete
         }
     }
 

+ 2 - 0
Rx.NET/Source/System.Reactive.PlatformServices/Reactive/EnlightenmentProvider.cs

@@ -25,7 +25,9 @@ namespace System.Reactive.PlatformServices
         /// </returns>
         public static bool EnsureLoaded()
         {
+#pragma warning disable CS0618
             return PlatformEnlightenmentProvider.Current is CurrentPlatformEnlightenmentProvider;
+#pragma warning restore CS0618
         }
     }
 }

+ 11 - 4
Rx.NET/Source/Tests.System.Reactive/Tests/Concurrency/SchedulerTest.cs

@@ -2,7 +2,6 @@
 // The .NET Foundation licenses this file to you under the Apache 2.0 License.
 // See the LICENSE file in the project root for more information. 
 
-#if NET45
 using System;
 using System.Collections.Generic;
 using System.Linq;
@@ -57,9 +56,11 @@ namespace ReactiveTests.Tests
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.CurrentThread.Schedule(default(Action)));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.CurrentThread.Schedule(TimeSpan.Zero, default(Action)));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.CurrentThread.Schedule(DateTimeOffset.MaxValue, default(Action)));
+#if DESKTOPCLR
             ReactiveAssert.Throws<ArgumentNullException>(() => DispatcherScheduler.Instance.Schedule(default(Action)));
             ReactiveAssert.Throws<ArgumentNullException>(() => DispatcherScheduler.Instance.Schedule(TimeSpan.Zero, default(Action)));
             ReactiveAssert.Throws<ArgumentNullException>(() => DispatcherScheduler.Instance.Schedule(DateTimeOffset.MaxValue, default(Action)));
+#endif
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.Immediate.Schedule(default(Action)));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.Immediate.Schedule(TimeSpan.Zero, default(Action)));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.Immediate.Schedule(DateTimeOffset.MaxValue, default(Action)));
@@ -216,6 +217,8 @@ namespace ReactiveTests.Tests
         #region ISchedulerLongRunning
 
 #if !NO_PERF
+
+#if !WINDOWS && !NO_THREAD
         [Fact]
         public void Scheduler_LongRunning_ArgumentChecking()
         {
@@ -238,6 +241,7 @@ namespace ReactiveTests.Tests
             ReactiveAssert.Throws<ArgumentOutOfRangeException>(() => Scheduler.SchedulePeriodic<int>(ThreadPoolScheduler.Instance, 42, TimeSpan.FromSeconds(-1), _ => _));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.SchedulePeriodic<int>(ThreadPoolScheduler.Instance, 42, TimeSpan.FromSeconds(1), default(Func<int, int>)));
         }
+#endif
 
         [Fact]
         public void Scheduler_Stopwatch_Emulation()
@@ -295,6 +299,8 @@ namespace ReactiveTests.Tests
         #region ISchedulerPeriodic
 
 #if !NO_PERF
+
+#if !WINDOWS && !NO_THREAD
         [Fact]
         public void Scheduler_Periodic1()
         {
@@ -328,6 +334,7 @@ namespace ReactiveTests.Tests
             e.WaitOne();
             d.Dispose();
         }
+#endif
 
 #if DESKTOPCLR
         [Fact]
@@ -427,7 +434,7 @@ namespace ReactiveTests.Tests
 
 #endif
 
-        #endregion
+#endregion
 
         #region DisableOptimizations
 
@@ -437,8 +444,9 @@ namespace ReactiveTests.Tests
         {
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(default(IScheduler)));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(default(IScheduler), new Type[0]));
+#if !WINDOWS && !NO_THREAD
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(ThreadPoolScheduler.Instance, default(Type[])));
-
+#endif
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(Scheduler.Default).Schedule(42, default(Func<IScheduler, int, IDisposable>)));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(Scheduler.Default).Schedule(42, TimeSpan.FromSeconds(1), default(Func<IScheduler, int, IDisposable>)));
             ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(Scheduler.Default).Schedule(42, DateTimeOffset.Now, default(Func<IScheduler, int, IDisposable>)));
@@ -1517,4 +1525,3 @@ namespace ReactiveTests.Tests
 #endif
     }
 }
-#endif