Cross应用程序中替换MvxDefaultViewModelL

Cross应用程序中替换MvxDefaultViewModelL

本文介绍了如何在MVVMCross应用程序中替换MvxDefaultViewModelLocator的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想滚动自己的ViewModelLocator在应用程序的中心位置为ViewModel创建提供一个try/catch/log包装器,为了能够做到这一点,我必须替换默认的MvxDefaultViewModelLocator.但是我没有找到一种替代通用方法的方法,只能注入特定于VM类型的方法.

I'd like to roll my own ViewModelLocator to provide a try/catch/log wrapper for ViewModel creation at a central place within the application, to be able to do it I've to replace the default MvxDefaultViewModelLocator. But I did not find a way to replace the generic one, only to inject a VM type specific one.

我应该如何将自己的ViewModelLocator类作为默认类注入?

How should I inject my own ViewModelLocator class as a default one?

推荐答案

我只是重新阅读了您的问题....我回答了另一个问题,不是吗?抱歉!

I just reread your question.... and I answered a different one, didn't I? Sorry!

让我们再试一次...

Let's try again...

默认的MvxApplication不提供任何方法来覆盖此成员.如果您认为这样做很有用,那么一定会引发问题或对GitHub造成影响.

The default MvxApplication doesn't provide any way to override this member. If you think it would be useful to, then by all means raise an issue or a pull on GitHub.

但是,在不更改Mvx代码的情况下,实现我认为正在寻找的效果的一种方法是简单地替换IoC/ServiceProvider框架中的IMvxViewModelLocatorFinder接口-您可以轻松实现:

However, without changing the Mvx code, then one way to achieve the effect that I think you are looking for is to simply replace the IMvxViewModelLocatorFinder interface in the IoC/ServiceProvider framework - you could easily implement:

  public class MyFinder : IMvxViewModelLocatorFinder
  {
        public IMvxViewModelLocator FindLocator(MvxShowViewModelRequest request)
       {

            return new MyDefaultViewModelLocator();
       }
  }

,然后您可以在安装程序的InitializeLastChance部分中为每个客户端项目注入它(覆盖IoC中的Application项)?

and you could then inject this (overwriting the Application entry in IoC) during the InitializeLastChance part of Setup for each of the client projects?

或者,如果您愿意的话,您可以走得更高-您可以代替IMvxViewModelLoader

Alternatively, you could go even higher if you wanted to - you could replace IMvxViewModelLoader instead

这篇关于如何在MVVMCross应用程序中替换MvxDefaultViewModelLocator的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 22:54