Skip to content

Commit 8451c8c

Browse files
authored
Replace Locator.Current with AppLocator.Current (#4217)
<!-- Please be sure to read the [Contribute](https://github.com/reactiveui/reactiveui#contribute) section of the README --> **What kind of change does this PR introduce?** <!-- Bug fix, feature, docs update, ... --> update **What is the new behavior?** <!-- If this is a feature change --> Updated all usages of Locator.Current and Locator.CurrentMutable to AppLocator.Current and AppLocator.CurrentMutable across the codebase. This change standardizes dependency resolution and improves clarity regarding the application's service locator. **What might this PR break?** Locator usage replaced with underlying AppLocator, not expecting breaking change **Please check if the PR fulfills these requirements** - [ ] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been added / updated (for bug fixes / features) **Other information**:
1 parent 3bfb979 commit 8451c8c

19 files changed

+29
-37
lines changed

src/ReactiveUI.Maui/Common/RoutedViewHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public RoutedViewHost()
4949
HorizontalContentAlignment = HorizontalAlignment.Stretch;
5050
VerticalContentAlignment = VerticalAlignment.Stretch;
5151

52-
var platform = Locator.Current.GetService<IPlatformOperations>();
52+
var platform = AppLocator.Current.GetService<IPlatformOperations>();
5353
Func<string?> platformGetter = () => default;
5454

5555
if (platform is null)

src/ReactiveUI.Maui/Common/ViewModelViewHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public partial class ViewModelViewHost : TransitioningContentControl, IViewFor,
4949
#endif
5050
public ViewModelViewHost()
5151
{
52-
var platform = Locator.Current.GetService<IPlatformOperations>();
52+
var platform = AppLocator.Current.GetService<IPlatformOperations>();
5353
Func<string?> platformGetter = () => default;
5454

5555
if (platform is null)

src/ReactiveUI.Maui/ReactiveShellContent.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public partial class ReactiveShellContent<TViewModel> : ShellContent, IActivatab
4747
/// </summary>
4848
public ReactiveShellContent()
4949
{
50-
var view = Locator.Current.GetService<IViewFor<TViewModel>>(Contract);
50+
var view = AppLocator.Current.GetService<IViewFor<TViewModel>>(Contract);
5151
if (view is not null)
5252
{
5353
ContentTemplate = new DataTemplate(() => view);
@@ -80,14 +80,14 @@ public string? Contract
8080

8181
private static void ViewModelChanged(BindableObject bindable, object oldValue, object newValue)
8282
{
83-
if (Locator.Current is null)
83+
if (AppLocator.Current is null)
8484
{
85-
throw new NullReferenceException(nameof(Locator.Current));
85+
throw new NullReferenceException(nameof(AppLocator.Current));
8686
}
8787

8888
if (bindable is ReactiveShellContent<TViewModel> svm)
8989
{
90-
var view = Locator.Current.GetService<IViewFor<TViewModel>>(svm.Contract);
90+
var view = AppLocator.Current.GetService<IViewFor<TViewModel>>(svm.Contract);
9191
if (view is not null)
9292
{
9393
svm.ContentTemplate = new DataTemplate(() => view);

src/ReactiveUI.Maui/RoutedViewHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public RoutedViewHost()
161161
await SyncNavigationStacksAsync();
162162
});
163163

164-
var screen = Locator.Current.GetService<IScreen>() ?? throw new Exception("You *must* register an IScreen class representing your App's main Screen");
164+
var screen = AppLocator.Current.GetService<IScreen>() ?? throw new Exception("You *must* register an IScreen class representing your App's main Screen");
165165
Router = screen.Router;
166166
}
167167

src/ReactiveUI.Winforms/ReactiveUI.Winforms.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<Compile Include="..\ReactiveUI.Wpf\Rx\**\*.cs" LinkBase="Rx" Exclude="..\ReactiveUI.Wpf\Rx\**\Dispatcher*.cs;..\ReactiveUI.Wpf\Rx\Internal\*.cs;..\ReactiveUI.Wpf\Rx\Concurrency\*.cs;..\ReactiveUI.Wpf\Rx\Linq\ControlObservable.cs" />
2121
</ItemGroup>
2222

23-
<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) or $(TargetFramework.EndsWith('-windows10.0.17763.0'))">
23+
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
2424
<Compile Include="..\ReactiveUI.Wpf\Rx\Concurrency\ControlScheduler.cs" LinkBase="Rx\Concurrency" />
2525
</ItemGroup>
2626
</Project>

src/ReactiveUI.Wpf/Common/RoutedViewHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public RoutedViewHost()
7171
HorizontalContentAlignment = HorizontalAlignment.Stretch;
7272
VerticalContentAlignment = VerticalAlignment.Stretch;
7373

74-
var platform = Locator.Current.GetService<IPlatformOperations>();
74+
var platform = AppLocator.Current.GetService<IPlatformOperations>();
7575
Func<string?> platformGetter = () => default;
7676

7777
if (platform is null)

src/ReactiveUI.Wpf/Common/ViewModelViewHost.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public ViewModelViewHost()
7878
DefaultStyleKey = typeof(ViewModelViewHost);
7979
#endif
8080

81-
var platform = Locator.Current.GetService<IPlatformOperations>();
81+
var platform = AppLocator.Current.GetService<IPlatformOperations>();
8282
Func<string?> platformGetter = () => default;
8383

8484
if (platform is null)

src/ReactiveUI.Wpf/ReactiveUI.Wpf.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<Compile Remove="Rx\Internal\Constants.cs;Rx\**\Dispatcher*.cs;Rx\**\Control*.cs" />
1818
</ItemGroup>
1919

20-
<ItemGroup Condition="$(TargetFramework.StartsWith('net46')) or $(TargetFramework.EndsWith('-windows10.0.17763.0'))">
20+
<ItemGroup Condition="$(TargetFramework.StartsWith('net46'))">
2121
<Compile Include="Rx\Internal\Constants.cs;Rx\**\Dispatcher*.cs" />
2222
</ItemGroup>
2323
</Project>

src/ReactiveUI.Wpf/Rx/Concurrency/DispatcherScheduler.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
namespace System.Reactive.Concurrency;
77

88
/// <summary>
9-
/// Represents an object that schedules units of work on a <see cref="System.Windows.Threading.Dispatcher"/>.
9+
/// The <see cref="DispatcherScheduler"/> schedules units of work on a <see cref="System.Windows.Threading.Dispatcher"/>.
1010
/// </summary>
11-
/// <remarks>
12-
/// This scheduler type is typically used indirectly through the <see cref="Linq.DispatcherObservable.ObserveOnDispatcher{TSource}(IObservable{TSource})"/> and <see cref="Linq.DispatcherObservable.SubscribeOnDispatcher{TSource}(IObservable{TSource})"/> methods that use the Dispatcher on the calling thread.
13-
/// </remarks>
11+
/// <seealso cref="System.Reactive.Concurrency.LocalScheduler" />
12+
/// <seealso cref="System.Reactive.Concurrency.ISchedulerPeriodic" />
1413
public class DispatcherScheduler : LocalScheduler, ISchedulerPeriodic
1514
{
1615
/// <summary>

src/ReactiveUI/Activation/ViewForMixins.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static class ViewForMixins
1515
private static readonly MemoizingMRUCache<Type, IActivationForViewFetcher?> _activationFetcherCache =
1616
new(
1717
(t, _) =>
18-
Locator.Current
18+
AppLocator.Current
1919
.GetServices<IActivationForViewFetcher?>()
2020
.Aggregate((count: 0, viewFetcher: default(IActivationForViewFetcher?)), (acc, x) =>
2121
{

0 commit comments

Comments
 (0)