Skip to content

Feature Introduce ReactiveUIBuilder #4086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<CentralPackageTransitivePinningEnabled>true</CentralPackageTransitivePinningEnabled>
</PropertyGroup>
<PropertyGroup>
<SplatVersion>15.4.1</SplatVersion>
<SplatVersion>15.5.3</SplatVersion>
<XamarinAndroidXCoreVersion>1.13.1.4</XamarinAndroidXCoreVersion>
<XamarinAndroidXLifecycleLiveDataVersion>2.8.4.1</XamarinAndroidXLifecycleLiveDataVersion>
</PropertyGroup>
Expand Down
3 changes: 0 additions & 3 deletions src/ReactiveUI.AOTTests/AOTCompatibilityTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Reactive.Linq;
using ReactiveUI;
using Xunit;

namespace ReactiveUI.AOTTests;

Expand Down
3 changes: 0 additions & 3 deletions src/ReactiveUI.AOTTests/AdvancedAOTTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,10 @@
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using ReactiveUI;
using Splat;
using Xunit;

namespace ReactiveUI.AOTTests;

Expand Down
3 changes: 0 additions & 3 deletions src/ReactiveUI.AOTTests/ComprehensiveAOTMarkupTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using ReactiveUI;
using Splat;
using Xunit;

namespace ReactiveUI.AOTTests;

Expand Down
3 changes: 0 additions & 3 deletions src/ReactiveUI.AOTTests/ComprehensiveAOTTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using ReactiveUI;
using Splat;
using Xunit;

namespace ReactiveUI.AOTTests;

Expand Down
2 changes: 0 additions & 2 deletions src/ReactiveUI.AOTTests/FinalAOTValidationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using ReactiveUI;
using Splat;
using Xunit;

namespace ReactiveUI.AOTTests;

Expand Down
2 changes: 0 additions & 2 deletions src/ReactiveUI.AOTTests/TestActivatableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;

namespace ReactiveUI.AOTTests;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/ReactiveUI.AOTTests/TestReactiveObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

using System.Diagnostics.CodeAnalysis;
using System.Reactive.Linq;
using ReactiveUI;

namespace ReactiveUI.AOTTests;

Expand Down
2 changes: 0 additions & 2 deletions src/ReactiveUI.AOTTests/TestRoutableViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using ReactiveUI;

namespace ReactiveUI.AOTTests;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/ReactiveUI.AndroidX/ReactiveAppCompatActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using Android.App;
using Android.Content;
using Android.Runtime;
Expand Down
2 changes: 0 additions & 2 deletions src/ReactiveUI.AndroidX/ReactiveFragment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

namespace ReactiveUI.AndroidX;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/ReactiveUI.AndroidX/ReactiveFragmentActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using Android.App;
using Android.Content;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;

namespace ReactiveUI.AndroidX;

/// <summary>
Expand Down
1 change: 0 additions & 1 deletion src/ReactiveUI.AndroidX/ReactiveRecyclerViewViewHolder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for full license information.

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;
Expand Down
57 changes: 57 additions & 0 deletions src/ReactiveUI.AndroidX/ReactiveUIBuilderAndroidXExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
// 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 full license information.

using Splat.Builder;

namespace ReactiveUI.AndroidX;

/// <summary>
/// AndroidX-specific extensions for ReactiveUIBuilder.
/// </summary>
public static class ReactiveUIBuilderAndroidXExtensions
{
/// <summary>
/// Registers AndroidX-specific services.
/// </summary>
/// <param name="builder">The builder instance.</param>
/// <returns>The builder instance for method chaining.</returns>
#if NET6_0_OR_GREATER
[RequiresDynamicCode("WithAndroidX uses methods that require dynamic code generation")]
[RequiresUnreferencedCode("WithAndroidX uses methods that may require unreferenced code")]
#endif
public static AppBuilder WithAndroidX(this Builder.ReactiveUIBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.WithPlatformModule<Registrations>();
}

/// <summary>
/// Registers AndroidX-specific services.
/// </summary>
/// <param name="builder">The builder instance.</param>
/// <returns>The builder instance for method chaining.</returns>
#if NET6_0_OR_GREATER
[RequiresDynamicCode("WithAndroidX uses methods that require dynamic code generation")]
[RequiresUnreferencedCode("WithAndroidX uses methods that may require unreferenced code")]
#endif
public static AppBuilder WithAndroidX(this AppBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

if (builder is not Builder.ReactiveUIBuilder reactiveUIBuilder)
{
throw new ArgumentException("The builder must be of type ReactiveUIBuilder.", nameof(builder));
}

return reactiveUIBuilder.WithPlatformModule<Registrations>();
}
}
44 changes: 44 additions & 0 deletions src/ReactiveUI.AndroidX/Registrations.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
// 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 full license information.

using Android.OS;

namespace ReactiveUI.AndroidX;

/// <summary>
/// AndroidX platform registrations.
/// </summary>
/// <seealso cref="ReactiveUI.IWantsToRegisterStuff" />
public class Registrations : IWantsToRegisterStuff
{
/// <inheritdoc/>
#if NET6_0_OR_GREATER
[RequiresDynamicCode("Register uses methods that require dynamic code generation")]
[RequiresUnreferencedCode("Register uses methods that may require unreferenced code")]
#endif
public void Register(Action<Func<object>, Type> registerFunction)
{
#if NET6_0_OR_GREATER
ArgumentNullException.ThrowIfNull(registerFunction);
#else
if (registerFunction is null)
{
throw new ArgumentNullException(nameof(registerFunction));
}
#endif

// Leverage core Android platform registrations already present in ReactiveUI.Platforms android.
// This ensures IPlatformOperations, binding converters, and schedulers are configured.
new PlatformRegistrations().Register(registerFunction);

// AndroidX specific registrations could be added here if needed in the future.

// Ensure a SynchronizationContext exists on Android when not in unit tests.
if (!ModeDetector.InUnitTestRunner() && Looper.MyLooper() is null)
{
Looper.Prepare();
}
}
}
57 changes: 57 additions & 0 deletions src/ReactiveUI.Blazor/ReactiveUIBuilderBlazorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
// 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 full license information.

using Splat.Builder;

namespace ReactiveUI.Blazor;

/// <summary>
/// Blazor-specific extensions for ReactiveUIBuilder.
/// </summary>
public static class ReactiveUIBuilderBlazorExtensions
{
/// <summary>
/// Registers Blazor-specific services.
/// </summary>
/// <param name="builder">The builder instance.</param>
/// <returns>The builder instance for method chaining.</returns>
#if NET6_0_OR_GREATER
[RequiresDynamicCode("WithBlazor uses methods that require dynamic code generation")]
[RequiresUnreferencedCode("WithBlazor uses methods that may require unreferenced code")]
#endif
public static AppBuilder WithBlazor(this Builder.ReactiveUIBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.WithPlatformModule<Registrations>();
}

/// <summary>
/// Registers Blazor-specific services.
/// </summary>
/// <param name="builder">The builder instance.</param>
/// <returns>The builder instance for method chaining.</returns>
#if NET6_0_OR_GREATER
[RequiresDynamicCode("WithBlazor uses methods that require dynamic code generation")]
[RequiresUnreferencedCode("WithBlazor uses methods that may require unreferenced code")]
#endif
public static AppBuilder WithBlazor(this AppBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

if (builder is not Builder.ReactiveUIBuilder reactiveUIBuilder)
{
throw new ArgumentException("The builder must be of type ReactiveUIBuilder.", nameof(builder));
}

return reactiveUIBuilder.WithPlatformModule<Registrations>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net8.0;net9.0;net8.0-windows10.0.19041.0;net9.0-windows10.0.19041.0</TargetFrameworks>
<UseMaui>true</UseMaui>
<NoWarn>$(NoWarn);CS1591;SA1600</NoWarn>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\ReactiveUI.Maui\ReactiveUI.Maui.csproj" />
<ProjectReference Include="..\ReactiveUI\ReactiveUI.csproj" />
</ItemGroup>
<ItemGroup>
<Using Include="Xunit" />
<Using Include="Splat" />
</ItemGroup>
</Project>
44 changes: 44 additions & 0 deletions src/ReactiveUI.Builder.Maui.Tests/ReactiveUIBuilderMauiTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright (c) 2025 .NET Foundation and Contributors. All rights reserved.
// 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 full license information.

using ReactiveUI.Maui;
using Splat.Builder;

namespace ReactiveUI.Builder.Maui.Tests;

public class ReactiveUIBuilderMauiTests
{
[Fact]
public void WithMaui_Should_Register_Services()
{
AppBuilder.ResetBuilderStateForTests();
using var locator = new ModernDependencyResolver();

locator.CreateBuilder()
.WithMaui()
.Build();

var typeConverters = locator.GetServices<IBindingTypeConverter>();
Assert.NotNull(typeConverters);
}

[Fact]
public void WithCoreServices_AndMaui_Should_Register_All_Services()
{
AppBuilder.ResetBuilderStateForTests();
using var locator = new ModernDependencyResolver();

locator.CreateBuilder()
.WithCoreServices()
.WithMaui()
.Build();

var observableProperty = locator.GetService<ICreatesObservableForProperty>();
Assert.NotNull(observableProperty);

var typeConverters = locator.GetServices<IBindingTypeConverter>();
Assert.NotNull(typeConverters);
}
}
Loading
Loading