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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
27 changes: 27 additions & 0 deletions src/ReactiveUI.Blazor/ReactiveUIBuilderBlazorExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

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>
public static Builder.ReactiveUIBuilder WithBlazor(this Builder.ReactiveUIBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.WithPlatformModule<Registrations>();
}
}
27 changes: 27 additions & 0 deletions src/ReactiveUI.Drawing/ReactiveUIBuilderDrawingExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

namespace ReactiveUI.Drawing;

/// <summary>
/// Drawing-specific extensions for ReactiveUIBuilder.
/// </summary>
public static class ReactiveUIBuilderDrawingExtensions
{
/// <summary>
/// Registers Drawing-specific services.
/// </summary>
/// <param name="builder">The builder instance.</param>
/// <returns>The builder instance for method chaining.</returns>
public static Builder.ReactiveUIBuilder WithDrawing(this Builder.ReactiveUIBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.WithPlatformModule<Registrations>();
}
}
27 changes: 27 additions & 0 deletions src/ReactiveUI.Maui/ReactiveUIBuilderMauiExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

namespace ReactiveUI.Maui;

/// <summary>
/// MAUI-specific extensions for ReactiveUIBuilder.
/// </summary>
public static class ReactiveUIBuilderMauiExtensions
{
/// <summary>
/// Registers MAUI-specific services.
/// </summary>
/// <param name="builder">The builder instance.</param>
/// <returns>The builder instance for method chaining.</returns>
public static Builder.ReactiveUIBuilder WithMaui(this Builder.ReactiveUIBuilder builder)
{
if (builder is null)
{
throw new ArgumentNullException(nameof(builder));
}

return builder.WithPlatformModule<Registrations>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ namespace ReactiveUI
public System.IDisposable DelayChangeNotifications() { }
public System.IDisposable SuppressChangeNotifications() { }
}
public static class ReactiveUIBuilderExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder CreateBuilder(this Splat.IMutableDependencyResolver resolver) { }
}
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public static class Reflection
Expand Down Expand Up @@ -1255,3 +1259,28 @@ namespace ReactiveUI
where TSender : class { }
}
}
namespace ReactiveUI.Builder
{
public interface IReactiveUIModule
{
void Configure(Splat.IMutableDependencyResolver resolver);
}
public sealed class ReactiveUIBuilder
{
public ReactiveUIBuilder(Splat.IMutableDependencyResolver resolver) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public void Build() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public ReactiveUI.Builder.ReactiveUIBuilder WithCoreServices() { }
public ReactiveUI.Builder.ReactiveUIBuilder WithCustomRegistration(System.Action<Splat.IMutableDependencyResolver> configureAction) { }
public ReactiveUI.Builder.ReactiveUIBuilder WithModule(ReactiveUI.Builder.IReactiveUIModule registrationModule) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public ReactiveUI.Builder.ReactiveUIBuilder WithPlatformServices() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public ReactiveUI.Builder.ReactiveUIBuilder WithViewsFromAssembly(System.Reflection.Assembly assembly) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,10 @@ namespace ReactiveUI
public System.IDisposable DelayChangeNotifications() { }
public System.IDisposable SuppressChangeNotifications() { }
}
public static class ReactiveUIBuilderExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder CreateBuilder(this Splat.IMutableDependencyResolver resolver) { }
}
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public static class Reflection
Expand Down Expand Up @@ -1255,3 +1259,28 @@ namespace ReactiveUI
where TSender : class { }
}
}
namespace ReactiveUI.Builder
{
public interface IReactiveUIModule
{
void Configure(Splat.IMutableDependencyResolver resolver);
}
public sealed class ReactiveUIBuilder
{
public ReactiveUIBuilder(Splat.IMutableDependencyResolver resolver) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public void Build() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public ReactiveUI.Builder.ReactiveUIBuilder WithCoreServices() { }
public ReactiveUI.Builder.ReactiveUIBuilder WithCustomRegistration(System.Action<Splat.IMutableDependencyResolver> configureAction) { }
public ReactiveUI.Builder.ReactiveUIBuilder WithModule(ReactiveUI.Builder.IReactiveUIModule registrationModule) { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public ReactiveUI.Builder.ReactiveUIBuilder WithPlatformServices() { }
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("The method uses reflection and will not work in AOT environments.")]
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("The method uses reflection and will not work in AOT environments.")]
public ReactiveUI.Builder.ReactiveUIBuilder WithViewsFromAssembly(System.Reflection.Assembly assembly) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,10 @@ namespace ReactiveUI
public System.IDisposable DelayChangeNotifications() { }
public System.IDisposable SuppressChangeNotifications() { }
}
public static class ReactiveUIBuilderExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder CreateBuilder(this Splat.IMutableDependencyResolver resolver) { }
}
public static class Reflection
{
public static string ExpressionToPropertyNames(System.Linq.Expressions.Expression? expression) { }
Expand Down Expand Up @@ -1148,3 +1152,20 @@ namespace ReactiveUI
where TSender : class { }
}
}
namespace ReactiveUI.Builder
{
public interface IReactiveUIModule
{
void Configure(Splat.IMutableDependencyResolver resolver);
}
public sealed class ReactiveUIBuilder
{
public ReactiveUIBuilder(Splat.IMutableDependencyResolver resolver) { }
public void Build() { }
public ReactiveUI.Builder.ReactiveUIBuilder WithCoreServices() { }
public ReactiveUI.Builder.ReactiveUIBuilder WithCustomRegistration(System.Action<Splat.IMutableDependencyResolver> configureAction) { }
public ReactiveUI.Builder.ReactiveUIBuilder WithModule(ReactiveUI.Builder.IReactiveUIModule registrationModule) { }
public ReactiveUI.Builder.ReactiveUIBuilder WithPlatformServices() { }
public ReactiveUI.Builder.ReactiveUIBuilder WithViewsFromAssembly(System.Reflection.Assembly assembly) { }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace ReactiveUI.Winforms
public PlatformOperations() { }
public string? GetOrientation() { }
}
public static class ReactiveUIBuilderWinFormsExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder WithWinForms(this ReactiveUI.Builder.ReactiveUIBuilder builder) { }
}
public class ReactiveUserControlNonGeneric : System.Windows.Forms.UserControl, ReactiveUI.IActivatableView, ReactiveUI.IViewFor
{
public ReactiveUserControlNonGeneric() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace ReactiveUI.Winforms
public PlatformOperations() { }
public string? GetOrientation() { }
}
public static class ReactiveUIBuilderWinFormsExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder WithWinForms(this ReactiveUI.Builder.ReactiveUIBuilder builder) { }
}
public class ReactiveUserControlNonGeneric : System.Windows.Forms.UserControl, ReactiveUI.IActivatableView, ReactiveUI.IViewFor
{
public ReactiveUserControlNonGeneric() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ namespace ReactiveUI.Winforms
public PlatformOperations() { }
public string? GetOrientation() { }
}
public static class ReactiveUIBuilderWinFormsExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder WithWinForms(this ReactiveUI.Builder.ReactiveUIBuilder builder) { }
}
public class ReactiveUserControlNonGeneric : System.Windows.Forms.UserControl, ReactiveUI.IActivatableView, ReactiveUI.IViewFor
{
public ReactiveUserControlNonGeneric() { }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.Winforms;

namespace ReactiveUI.Tests.Platforms.Winforms;

/// <summary>
/// Tests for WinForms-specific ReactiveUIBuilder functionality.
/// </summary>
public class ReactiveUIBuilderWinFormsTests
{
/// <summary>
/// Test that WinForms services can be registered using the builder.
/// </summary>
[Fact]
public void WithWinForms_Should_Register_WinForms_Services()
{
// Arrange
using var locator = new ModernDependencyResolver();
var builder = locator.CreateBuilder();

// Act
builder.WithWinForms().Build();

// Assert
var platformOperations = locator.GetService<IPlatformOperations>();
Assert.NotNull(platformOperations);

var activationFetcher = locator.GetService<IActivationForViewFetcher>();
Assert.NotNull(activationFetcher);
}

/// <summary>
/// Test that the builder can chain WinForms registration with core services.
/// </summary>
[Fact]
public void WithCoreServices_AndWinForms_Should_Register_All_Services()
{
// Arrange
using var locator = new ModernDependencyResolver();
var builder = locator.CreateBuilder();

// Act
builder.WithCoreServices().WithWinForms().Build();

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

// WinForms-specific services
var platformOperations = locator.GetService<IPlatformOperations>();
Assert.NotNull(platformOperations);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ namespace ReactiveUI
}
namespace ReactiveUI.Wpf
{
public static class ReactiveUIBuilderWpfExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder WithWpf(this ReactiveUI.Builder.ReactiveUIBuilder builder) { }
}
public class Registrations
{
public Registrations() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ namespace ReactiveUI
}
namespace ReactiveUI.Wpf
{
public static class ReactiveUIBuilderWpfExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder WithWpf(this ReactiveUI.Builder.ReactiveUIBuilder builder) { }
}
public class Registrations
{
public Registrations() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ namespace ReactiveUI
}
namespace ReactiveUI.Wpf
{
public static class ReactiveUIBuilderWpfExtensions
{
public static ReactiveUI.Builder.ReactiveUIBuilder WithWpf(this ReactiveUI.Builder.ReactiveUIBuilder builder) { }
}
public class Registrations
{
public Registrations() { }
Expand Down
58 changes: 58 additions & 0 deletions src/ReactiveUI.Tests/Platforms/wpf/ReactiveUIBuilderWpfTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.Wpf;

namespace ReactiveUI.Tests.Platforms.Wpf;

/// <summary>
/// Tests for WPF-specific ReactiveUIBuilder functionality.
/// </summary>
public class ReactiveUIBuilderWpfTests
{
/// <summary>
/// Test that WPF services can be registered using the builder.
/// </summary>
[Fact]
public void WithWpf_Should_Register_Wpf_Services()
{
// Arrange
using var locator = new ModernDependencyResolver();
var builder = locator.CreateBuilder();

// Act
builder.WithWpf().Build();

// Assert
var platformOperations = locator.GetService<IPlatformOperations>();
Assert.NotNull(platformOperations);

var activationFetcher = locator.GetService<IActivationForViewFetcher>();
Assert.NotNull(activationFetcher);
}

/// <summary>
/// Test that the builder can chain WPF registration with core services.
/// </summary>
[Fact]
public void WithCoreServices_AndWpf_Should_Register_All_Services()
{
// Arrange
using var locator = new ModernDependencyResolver();
var builder = locator.CreateBuilder();

// Act
builder.WithCoreServices().WithWpf().Build();

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

// WPF-specific services
var platformOperations = locator.GetService<IPlatformOperations>();
Assert.NotNull(platformOperations);
}
}
Loading
Loading