Repository navigation
Add RxAppBuilder docs and update .NET SDK to 10 preview #906
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
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| { | ||
| "msbuild-sdks": { | ||
| "MSBuild.Sdk.Extras": "3.0.44" | ||
| } | ||
| "sdk": { | ||
| "version": "10.0.100-rc.2.25502.107", | ||
| "rollForward": "latestFeature", | ||
| "allowPrerelease": true | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| # RxAppBuilder in ReactiveUI - introduced in V21.0.1 | ||
|
|
||
| The `RxAppBuilder` class in ReactiveUI is responsible for initializing and configuring the ReactiveUI framework within your application. | ||
| It provides a fluent API to set up various components and services that ReactiveUI relies on. | ||
| It extends the capabilities of the Splat Builder and Splat AppLocator to register platform-specific services, views, view models, and other dependencies required for ReactiveUI to function correctly. | ||
|
|
||
| ## Key Features of RxAppBuilder | ||
| - **Fluent Configuration**: The `RxAppBuilder` class allows you to chain configuration methods to set up your application in a readable and maintainable way. | ||
| - **Service Registration**: You can register services and dependencies that your application will use, such as view models, views, and other services. | ||
| - **Platform Integration**: It provides methods to integrate ReactiveUI with different platforms, ensuring that the framework works seamlessly across various environments. | ||
| - **Customization**: You can customize the behavior of ReactiveUI by configuring options and settings that suit your application's needs. | ||
| - **Initialization**: The `RxAppBuilder` class includes methods to initialize the ReactiveUI framework, ensuring that all necessary components are set up before your application starts. | ||
|
|
||
| ## Example Usage | ||
| ```csharp | ||
| var rxuiInstance = RxAppBuilder.CreateReactiveUIBuilder() | ||
| .WithWpf() // Register WPF platform services | ||
| .WithViewsFromAssembly(typeof(App).Assembly) // Register views and view models | ||
| .WithRegistration(locator => | ||
| { | ||
| // Register IScreen as a singleton so all resolutions share the same Router | ||
| locator.RegisterLazySingleton<IScreen>(static () => new AppBootstrapper()); | ||
| }) | ||
| .BuildApp(); | ||
|
|
||
| var mainUIThreadScheduler = rxuiInstance.MainThreadScheduler; | ||
| var taskpoolScheduler = rxuiInstance.TaskpoolScheduler; | ||
| ``` | ||
|
|
||
| ## Platform Support | ||
| The `RxAppBuilder` class supports various platforms, including WPF, Xamarin.Forms, and others. You can use platform-specific methods to ensure that ReactiveUI is properly configured for the target environment. | ||
|
|
||
| ReactiveUI.AndroidX - `WithAndroidX()` | ||
| ReactiveUI.WPF - `WithWpf()` | ||
| ReactiveUI.Maui - `WithMaui()` | ||
| ReactiveUI.Blazor - `WithBlazor()` | ||
| ReactiveUI.WinForms - `WithWinForms()` | ||
| ReactiveUI.WinUI - `WithWinUI()` | ||
|
|
||
| ## Registering Views and ViewModels | ||
| You can register views and view models from specific assemblies using the `WithViewsFromAssembly` method. This allows ReactiveUI to automatically discover and register your views and view models. | ||
| ```csharp | ||
| .WithViewsFromAssembly(typeof(App).Assembly) | ||
| ``` | ||
| You can also register individual views and view models using the `WithView` and `WithViewModel` methods. | ||
| ```csharp | ||
| .RegisterView<MainView, MainViewModel>() | ||
| .RegisterSingletonView<SettingsView, SettingsViewModel>() | ||
| .RegisterViewModel<SettingsViewModel>() | ||
| .RegisterSingletonViewModel<SettingsViewModel>() | ||
| ``` | ||
|
|
||
| ## Custom Service Registration | ||
| You can register custom services and dependencies using the `WithPlatformModule` method. This allows you to integrate your own platform-specific services into the ReactiveUI framework. Where T is a class that implements IWantsToRegisterStuff. | ||
| ```csharp | ||
| .WithPlatformModule<Services.MyPlatformModule>() | ||
| ``` | ||
| ## Configure Schedulers | ||
| You can configure the main thread and task pool schedulers used by ReactiveUI using the `WithMainThreadScheduler` and `WithTaskpoolScheduler` methods. | ||
| ```csharp | ||
| .WithMainThreadScheduler(DispatcherScheduler.Current) | ||
| .WithTaskpoolScheduler(TaskPoolScheduler.Default) | ||
| ``` | ||
|
|
||
| The default scheduler extensions register the RxApp.MainThreadScheduler and RxApp.TaskpoolScheduler to use the appropriate schedulers for the platform. | ||
| This can be overridden by calling the above methods with `setRxApp = false` to prevent setting the RxApp static properties. | ||
|
|
||
| ```csharp | ||
| .WithMainThreadScheduler(DispatcherScheduler.Current, setRxApp: false) | ||
| .WithTaskpoolScheduler(TaskPoolScheduler.Default, setRxApp: false) | ||
| ``` | ||
|
|
||
| Each platform module also registers the appropriate default schedulers for that platform. | ||
| Custom schedulers can be provided as needed. | ||
| Each platform can be custom configured as needed. | ||
| By default the platform registers the appropriate `Schedulers` for that platform, the relevant `PlatformServices`, and the relevant `PlatformModule`. | ||
|
|
||
| ## Registration Options | ||
| The `RxAppBuilder` class provides various options for registering views, view models, and services. You can choose to register them as singletons or transient instances based on your application's requirements. | ||
|
|
||
| One option is to use an immediate registration approach, where services are registered directly within the builder configuration. | ||
| ```csharp | ||
| .WithRegistration(locator => | ||
| { | ||
| // Register IScreen as a singleton so all resolutions share the same Router, this is applied immediately | ||
| locator.RegisterLazySingleton<IScreen>(static () => new AppBootstrapper()); | ||
| }) | ||
| ``` | ||
| Another option is to use a deferred registration approach, where services are registered as the builder is built. | ||
| ```csharp | ||
| .WithRegistrationOnBuild(locator => | ||
| { | ||
| // Register IScreen as a singleton so all resolutions share the same Router, this is applied after BuildApp is called | ||
| locator.RegisterLazySingleton<IScreen>(static () => new AppBootstrapper()); | ||
| }) | ||
| ``` | ||
|
|
||
| ## Using Splat Modules | ||
| You can also use Splat modules to register services and dependencies. This allows you to leverage existing Splat modules or create your own for better organization. | ||
| ```csharp | ||
| .WithSplatModule(new MyCustomSplatModule()) | ||
| .WithSplatModule<Services.MySplatModule>() | ||
| ``` | ||
|
|
||
| ## Building the App | ||
| Once you have configured the `RxAppBuilder`, you can build the ReactiveUI application instance using the `BuildApp` method. This finalizes the configuration and prepares the application for use. | ||
| ```csharp | ||
| var rxuiInstance = rxAppBuilder.BuildApp(); | ||
| var mainUIThreadScheduler = rxuiInstance.MainThreadScheduler; | ||
| var taskpoolScheduler = rxuiInstance.TaskpoolScheduler; | ||
| ``` | ||
|
|
||
| ## WithInstance usage | ||
| This allows you to get instances from the underlying Splat service locator. | ||
| ```csharp | ||
| rxuiInstance.WithInstance<IScreen>(screen => | ||
| { // Use the registered IScreen instance for other services that depend on it. | ||
| screen.Router.Navigate.Execute(new MainViewModel(screen)); | ||
| }) | ||
| ``` | ||
|
|
||
| Up to 16 registered instances from Splat.AppLocator can be provided in a single WithInstance call. | ||
| ```csharp | ||
| rxuiInstance.WithInstance<IScreen, IDataService, ILogger>((screen, dataService, logger) => | ||
| { | ||
| // Use the registered instances for other services that depend on them. | ||
| }) | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't need a global.json weird that you are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's due to the fact that we are building all the repo's here, without it, the API's fail to be produced as the sln build fails. Once Net 10 becomes release and there is a VS2026 Action runner then this can be removed again.