如何在 MVMCross 应用程序中替换 MvxDefaultViewModelLocator [英] How to replace MvxDefaultViewModelLocator in MVVMCross application

查看:20
本文介绍了如何在 MVMCross 应用程序中替换 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!

我们再试一次...

默认的 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 中的应用程序条目)?

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

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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆