Skip to content

Commit 23ab0f0

Browse files
authored
Ensure Splat initialization in builder and tests (#4098)
<!-- 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, feature **What is the new behavior?** <!-- If this is a feature change --> Added calls to InitializeSplat in ReactiveUIBuilder, builder extension, and RxApp static constructor to ensure Splat services are registered before core ReactiveUI services. Updated test classes to call RxApp.EnsureInitialized in constructors for consistent initialization. Also updated Splat package version in Directory.Packages.props. **What might this PR break?** Part of a major update for V21 **Please check if the PR fulfills these requirements** - [x] Tests for the changes have been added (for bug fixes / features) - [ ] Docs have been added / updated (for bug fixes / features) **Other information**:
1 parent 219b20f commit 23ab0f0

File tree

9 files changed

+35
-2
lines changed

9 files changed

+35
-2
lines changed

src/Directory.Packages.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
55
</PropertyGroup>
66
<PropertyGroup>
7-
<SplatVersion>15.5.3</SplatVersion>
7+
<SplatVersion>16.0.1</SplatVersion>
88
<XamarinAndroidXCoreVersion>1.13.1.4</XamarinAndroidXCoreVersion>
99
<XamarinAndroidXLifecycleLiveDataVersion>2.8.4.1</XamarinAndroidXLifecycleLiveDataVersion>
1010
</PropertyGroup>

src/ReactiveUI.AOTTests/ViewLocatorAOTMappingTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ namespace ReactiveUI.AOTTests;
1212
/// </summary>
1313
public class ViewLocatorAOTMappingTests
1414
{
15+
/// <summary>
16+
/// Initializes a new instance of the <see cref="ViewLocatorAOTMappingTests"/> class.
17+
/// </summary>
18+
public ViewLocatorAOTMappingTests()
19+
{
20+
RxApp.EnsureInitialized();
21+
}
22+
1523
/// <summary>
1624
/// Map/Resolve with contract and default fallback works.
1725
/// </summary>

src/ReactiveUI.Builder.Maui.Tests/ReactiveUIBuilderMauiTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public void WithCoreServices_AndMaui_Should_Register_All_Services()
3131
using var locator = new ModernDependencyResolver();
3232

3333
locator.CreateBuilder()
34-
.WithCoreServices()
3534
.WithMaui()
3635
.Build();
3736

src/ReactiveUI.Tests/Commands/ReactiveCommandTest.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@ namespace ReactiveUI.Tests;
1818
/// </summary>
1919
public class ReactiveCommandTest
2020
{
21+
public ReactiveCommandTest()
22+
{
23+
RxApp.EnsureInitialized();
24+
}
25+
2126
/// <summary>
2227
/// A test that determines whether this instance [can execute changed is available via ICommand].
2328
/// </summary>

src/ReactiveUI.Tests/Platforms/winforms/DefaultPropertyBindingTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ namespace ReactiveUI.Tests.Winforms;
1717
/// </summary>
1818
public class DefaultPropertyBindingTests
1919
{
20+
/// <summary>
21+
/// Initializes a new instance of the <see cref="DefaultPropertyBindingTests"/> class.
22+
/// </summary>
23+
public DefaultPropertyBindingTests()
24+
{
25+
RxApp.EnsureInitialized();
26+
}
27+
2028
/// <summary>
2129
/// Tests Winforms creates observable for property works for textboxes.
2230
/// </summary>

src/ReactiveUI.Tests/Platforms/wpf/ReactiveUIBuilderWpfTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ namespace ReactiveUI.Tests.Platforms.Wpf;
1313
/// </summary>
1414
public class ReactiveUIBuilderWpfTests
1515
{
16+
/// <summary>
17+
/// Initializes a new instance of the <see cref="ReactiveUIBuilderWpfTests"/> class.
18+
/// </summary>
19+
public ReactiveUIBuilderWpfTests()
20+
{
21+
RxApp.EnsureInitialized();
22+
}
23+
1624
/// <summary>
1725
/// Test that WPF services can be registered using the builder.
1826
/// </summary>

src/ReactiveUI/Builder/ReactiveUIBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public override AppBuilder WithCoreServices()
3838
return this;
3939
}
4040

41+
_resolver.InitializeSplat();
42+
4143
// Immediately register the core ReactiveUI services into the provided resolver.
4244
var registrations = new Registrations();
4345
#pragma warning disable IL2067 // Target parameter argument does not satisfy 'DynamicallyAccessedMembersAttribute' in call to target method. The parameter of method does not have matching annotations.

src/ReactiveUI/Mixins/ReactiveUIBuilderExtensions.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public static class ReactiveUIBuilderExtensions
2626
public static AppBuilder CreateBuilder(this IMutableDependencyResolver resolver)
2727
{
2828
resolver.ArgumentNullExceptionThrowIfNull(nameof(resolver));
29+
resolver.InitializeSplat();
2930
var builder = new Builder.ReactiveUIBuilder(resolver);
3031

3132
// Queue core registrations by default so Build() always provides the basics

src/ReactiveUI/RxApp.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static RxApp()
8484
#if !PORTABLE
8585
_taskpoolScheduler = TaskPoolScheduler.Default;
8686
#endif
87+
Locator.CurrentMutable.InitializeSplat();
8788

8889
if (!AppBuilder.UsingBuilder)
8990
{
@@ -94,6 +95,7 @@ static RxApp()
9495
return;
9596
}
9697

98+
Locator.CurrentMutable.InitializeSplat();
9799
Locator.CurrentMutable.InitializeReactiveUI(PlatformRegistrationManager.NamespacesToRegister);
98100
});
99101
}

0 commit comments

Comments
 (0)