Dependency injection IOC未解析依赖项-MVVMCross

Dependency injection IOC未解析依赖项-MVVMCross,dependency-injection,xamarin.ios,inversion-of-control,xamarin,mvvmcross,Dependency Injection,Xamarin.ios,Inversion Of Control,Xamarin,Mvvmcross,我对MVVMCross完全是个新手,但我正在尝试使用monotouch和Xamarin Studio以及github的最新MVVMCross二进制文件来实现依赖关系 找不到专门针对Xamarin Studio+Monocross的教程,所以在拼凑了一些教程之后,我有一些简单的控件可以很好地工作。然后,我尝试开始一些地图特征和一些DI。不幸的是,我收到错误消息,说无法解决依赖关系。我哪里做错了 // my view model using System; using Cirrious.MvvmCr

我对MVVMCross完全是个新手,但我正在尝试使用monotouch和Xamarin Studio以及github的最新MVVMCross二进制文件来实现依赖关系

找不到专门针对Xamarin Studio+Monocross的教程,所以在拼凑了一些教程之后,我有一些简单的控件可以很好地工作。然后,我尝试开始一些地图特征和一些DI。不幸的是,我收到错误消息,说无法解决依赖关系。我哪里做错了

// my view model
using System;
using Cirrious.MvvmCross.Plugins.Location;
using Cirrious.MvvmCross.ViewModels;
using Cirrious.CrossCore;

namespace mvxTest.Core
{

    public class MapViewModel : MvxViewModel
   {
            private IMvxLocationWatcher _watcher;

            public MapViewModel (IMvxLocationWatcher watcher) 
            {
                  // var resolved = Mvx.CanResolve<IMvxLocationWatcher> ();  // returns false
                  _watcher.Start (new MvxLocationOptions (), OnSuccess, OnError);
            }
    }
}



// my view
using System;
using Cirrious.MvvmCross.Touch.Views;
using MonoTouch.UIKit;
using System.Drawing;
using Cirrious.MvvmCross.Binding.BindingContext;
using mvxTest.Core;

namespace mvxTest.Touch
{

 // http://www.youtube.com/watch?v=MM9iQlx3quA
public class MapView : MvxViewController
{
    public MapView ()
    {
    }

    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();  // <-- breaks here with complaints 

        var label = new UILabel (new RectangleF (0, 100, 100, 50));
        label.BackgroundColor = UIColor.Blue;
        Add (label);

        var edit = new UITextView (new RectangleF (0, 200, 100, 50));
        edit.BackgroundColor = UIColor.Green;
        Add (edit);

        var binding = this.CreateBindingSet<MapView, MapViewModel> ();
        binding.Bind (label).To ((v) => v.Lat);
        binding.Bind (edit).To ((v) => v.Lng);
        binding.Apply ();
    }
}
}
//我的视图模型
使用制度;
使用cirries.MvvmCross.Plugins.Location;
使用cirries.MvvmCross.ViewModels;
使用cirrius.CrossCore;
名称空间mvxTest.Core
{
公共类MapViewModel:MvxViewModel
{
专用IMvxLocationWatcher\u watcher;
公共地图视图模型(IMvxLocationWatcher)
{
//var resolved=Mvx.CanResolve();//返回false
_启动(新的MvxLocationOptions(),OnSuccess,OnError);
}
}
}
//我的看法
使用制度;
使用cirries.MvvmCross.Touch.Views;
使用MonoTouch.UIKit;
使用系统图;
使用cirries.MvvmCross.Binding.BindingContext;
使用mvxTest.Core;
名称空间mvxTest.Touch
{
// http://www.youtube.com/watch?v=MM9iQlx3quA
公共类映射视图:MvxViewController
{
公共地图视图()
{
}
公共覆盖无效ViewDidLoad()
{
base.ViewDidLoad();//v.Lat);
绑定。绑定(编辑)到((v)=>v.Lng);
binding.Apply();
}
}
}
该错误令人困惑,因为它提到viewmodel依赖项未解析,但在触发viewdidload事件时会在视图中引发该错误。可能是加载视图模型的地方。无论如何,为什么不注入依赖项-我怀疑插件需要在monotouch项目中注册

2013-10-31 21:45:21.291 mvxTestTouch[9806:80b] mvx: Diagnostic:   0.20 Showing ViewModel MapViewModel
2013-10-31 21:45:21.294 mvxTestTouch[9806:80b] TouchNavigation: Diagnostic:   0.20 Navigate requested
2013-10-31 21:45:21.400 mvxTestTouch[9806:80b] mvx: Warning:   0.31 Problem creating viewModel of type MapViewModel - problem MvxException: Failed to resolve parameter for parameter watcher of type IMvxLocationWatcher when creating mvxTest.Core.MapViewModel
 at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00000] in <filename unknown>:0 
 at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in <filename unknown>:0 
 at Cirrious.CrossCore.Mvx.IocConstruct (System.Type t) [0x00000] in <filename unknown>:0 
 at Cirrious.MvvmCross.ViewModels.MvxDefaultViewModelLocator.TryLoad (System.Type viewModelType, IMvxBundle parameterValues, IMvxBundle savedState, IMvxViewModel& viewModel) [0x00000] in <filename unknown>:0 
2013-10-31 21:45:21.291 mvxTestTouch[9806:80b]mvx:Diagnostic:0.20显示ViewModel MapViewModel
2013-10-31 21:45:21.294 mvxTestTouch[9806:80b]触摸导航:诊断:0.20导航请求
2013-10-31 21:45:21.400 mvxTestTouch[9806:80b]mvx:警告:0.31创建MapViewModel类型的viewModel时出现问题-问题MVXeException:创建mvxTest.Core.MapViewModel时无法解析IMvxLocationWatcher类型的参数观察器的参数
在Cirrium.CrossCore.IoC.MvxSimpleIoCContainer.GetIoCParameterValues(System.Type类型,System.Reflection.ConstructorInfo firstConstructor)[0x00000]中:0
在cirrium.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct(System.Type)[0x00000]中:0
在cirrium.CrossCore.Mvx.IocConstruct(System.Type t)[0x00000]中:0
在Cirriary.MvvmCross.ViewModels.MvxDefaultViewModelLocator.TryLoad(System.Type viewModelType、IMvxBundle参数值、IMvxBundle保存状态、IMvxViewModel和viewModel)[0x00000]中:0
//更新

谢谢你的建议,斯图尔特-在看了N31+N8+N9之后,我在touch项目中加入了一个LocationPluginBootstrap并共享了相同的名称空间,效果很好-谢谢!!:

using Cirrious.CrossCore.Plugins;
using Cirrious.MvvmCross.Plugins.Location;
using Cirrious.MvvmCross.Plugins.Location.Touch;

namespace mvxTest.Touch
{
   public class LocationPluginBootstrap
    : MvxLoaderPluginBootstrapAction<PluginLoader,Plugin>
   {
   }
}
使用cirrius.CrossCore.Plugins;
使用cirries.MvvmCross.Plugins.Location;
使用cirries.MvvmCross.Plugins.Location.Touch;
名称空间mvxTest.Touch
{
公共类位置pluginbootstrap
:mvxloaderPluginBootstraction
{
}
}

IMvxLocationWatcher
是一个可选组件-位于插件中

要使插件可用,您需要引用插件核心和touch程序集,并且需要包含一个引导类,如


有关插件及其初始化的详细信息,请参阅IMvxLocationWatcher是一个可选组件,位于插件中

要使插件可用,您需要引用插件核心和touch程序集,并且需要包含一个引导类,如

有关插件及其初始化的详细信息,请参阅