-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improve the Initialization of RxUI #1737
Comments
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want this issue progressed faster please start a conversation about raising a pull-request or coordinating your pull-request with a maintainer to get it merged. Understand that if folks like yourself don't contribute, ReactiveUI won't grow. You may or may not know this but ReactiveUI is maintained by unpaid volunteers. The maintainers put up a big marketing front but at it's core is a couple of passionate folks. ReactiveUI cares about open-source sustainability as maintainers have a serious load on their shoulders. Consumers shouldn't be naive in thinking that the latest update to a nuget package just magically materializes from the ethers. These things happen because our peers make them happen. No-one wants a tragedy of the commons situation. I urge you to get involved. Thank-you. |
Ana came up with a point that at the moment on the platforms it works it works. On the original RFC there was the following comment
Just thinking we'd probably want to take advantage of the Target Framework where we can with a generic "Start()", maybe we can make this a extension method against our NuGet packages. Also our error messages have to be really consistent if we are in a non-initialized state if possible since at the moment the users really have to hunt the documentation. |
why not use something like: using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using Splat.Microsoft.Extensions.DependencyInjection;
// ...
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
using(var host = BuildHost(e.Args))
{
host.Start();
var services = host.Services;
services.UseMicrosoftDependencyResolver();
using (var mainScope = services.CreateScope())
{
var mainWindow = (Window) mainScope.ServiceProvider
.GetRequiredService<IViewFor<MainWindowViewModel>();
mainWindow.Show();
}
}
}
private IHost BuildHost(string[] args)
{
Host.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((builderContext, config) => {
IHostEnvironment env = builderContext.HostEnvironment;
config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);
// ...
})
.ConfigureServices(services => {
// configure Splat to use Microsoft DI
services.UseMicrosoftDependencyResolver();
var resolver = Splat.Locator.CurrentMutable;
resolver.InitializeSplat();
resolver.InitializeReactiveUI();
// add ReactiveUI
services.AddRxUI();
services.AddTransient<MainWindowViewModel>();
services.AddTransient<IViewFor<MainWindowViewModel>, MainWindow>();
// TODO: configure other services (user controls, viewmodels, services)
services.Configure<RxUIOptions>(options => {
options.UsePlatformSchedulers();
options.UsePlatformBindingConverters();
options.UsePlatformActivationForViewFetcher();
});
// TODO: configure other options
})
.ConfigureLogging(logger => {
// TODO: configure logging
})
.Build();
}
} Using Splat in ViewModel: public sealed MainViewModel : ReactiveObject, IActivatableViewModel
{
public MainViewModel()
{
var scopeFactory = Splat.Locator.Current.GetService<IServiceProvider>();
this.WhenActivated(d => {
var scope = scopeFactory.CreateScope().DisposeWith(d);
var services = scope.ServiceProvider;
// get other services from services
);
}
public ViewModelActivator Activator { get; } = new ViewModelActivator();
} |
I think the over all plan is to give the flexibility of some of the .NET Core Startup concepts, but keep a simple |
I know this is an old thread, but do we have an eta on delivering this? |
Use
|
Thanks @glennawatson The result, however, is that it still moans about trying to find XamForms (but at least it doesn't about the other platforms :) ) Also, this seems to happen when running the iOS project, but I'm not seeing it when running Android (likely because the startup code does touch anything reactiveUI related). |
This fixed the issue for me in my MAUI project(targeting net8.0-windows10.0.19041.0), I just called this before creating a new page: |
The Initialization of RxUI is a bit clunky at the moment
reactiveui/rfcs#14
Implement a change around the discussion in the RFC.
The text was updated successfully, but these errors were encountered: