reactiveui / Sextant

A ReactiveUI navigation library for Xamarin.Forms

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

performance: Remove activator

glennawatson opened this issue · comments

commented

Consider removing the activator here

() => Activator.CreateInstance(typeof(TView), mScheduler, bgScheduler, vLocator),

One way to remove it would be to do something like

 public static void RegisterNavigation<TView, TViewModel>(IScheduler mainThreadScheduler = null, IScheduler backgroundScheduler = null, IViewLocator viewLocator = null)
            where TView : new, IPageView, IViewFor
            where TViewModel : class, IPageViewModel
        {
            var bgScheduler = mainThreadScheduler ?? RxApp.TaskpoolScheduler;
            var mScheduler = backgroundScheduler ?? RxApp.MainThreadScheduler;
            var vLocator = viewLocator ?? Locator.Current.GetService<IViewLocator>();
            
            Locator.CurrentMutable.Register(
                () => new TView { Scheduler = mScheduler, BackgroundScheduler = bgScheduler, ViewLocator = vLocator },
                typeof(IViewFor<TViewModel>),
                "NavigationView");
        }

I had a couple of thoughts:

  1. Have the user explicitly pass an instance
  2. Resolve them from the Locator which would force registration on the user
  3. Take away the methods and bolster documentation on how to properly set this up yourself
  4. Provide an Initialize method similar to InitializeReactiveUI() so that all the Sextant bits get loaded Sextant.Initialize();.
  5. Apply extension mixins for View/ViewModel registration from the IMutableDependencyResolver

Specifically in the case of the NavigationView this alleviates a lot of boiler plate setup when 90% of the time IView is going to resolve to NavigationView unless you've overridden it. In which case I'd assume you'd know you need to register your implementation in the Locator