Skip to content

Expose public API for configuring DefaultExceptionHandler without builder #4302

@glennawatson

Description

@glennawatson

Context

Raised in #4296 by @ChaseFlorell. After upgrading, RxState.DefaultExceptionHandler only has a public getter — the InitializeExceptionHandler method is internal and only callable via ReactiveUIBuilder.WithExceptionHandler(). Users who have existing bootstrap pipelines (e.g., Blazor WASM, ASP.NET Core) and don't use RxAppBuilder have no way to set a custom exception handler.

Problem

// This used to work — now causes a compile error:
RxState.DefaultExceptionHandler = host.Services.GetService<IObserver<Exception>>();

The only path today is:

RxAppBuilder.CreateReactiveUIBuilder()
    .WithExceptionHandler(myHandler)
    .BuildApp();

For users with existing DI and bootstrap pipelines, this forces adoption of the full builder pattern just to set one global setting.

Proposed Solution

Add a public static method on RxState (or an extension method) that allows setting the exception handler directly:

// Option A: public setter method on RxState
RxState.SetDefaultExceptionHandler(myObserver);

// Option B: extension method on IMutableDependencyResolver
resolver.WithDefaultExceptionHandler(myObserver);

The builder's WithExceptionHandler should internally call the same public API. This keeps the builder as a convenience layer, not the only path.

Files Involved

  • src/ReactiveUI/RxState.cs — make InitializeExceptionHandler public or add a public wrapper
  • src/ReactiveUI/Builder/ReactiveUIBuilder.cs — call the public API internally

Acceptance Criteria

  • Users can configure DefaultExceptionHandler without using RxAppBuilder
  • The builder pattern continues to work as-is
  • Unit tests cover both paths
  • Update website documentation (see reactiveui/website issue)

Related: #4296

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions