Plugins MvvmCross将配置传递给可配置插件加载程序

Plugins MvvmCross将配置传递给可配置插件加载程序,plugins,mvvmcross,portable-class-library,Plugins,Mvvmcross,Portable Class Library,我正在创建一个便携式MockGeoLocationWatcher,人们可以用它代替IMvxGeoLocationWatcher的具体实现,直到有了一个实际的设备。这将有助于开发和测试需要地理定位的应用程序 此插件的PluginLoader类当前如下所示: namespace Pidac.MvvmCross.Plugins.Location { public class PluginLoader : IMvxConfigurablePluginLoader { pr

我正在创建一个便携式MockGeoLocationWatcher,人们可以用它代替IMvxGeoLocationWatcher的具体实现,直到有了一个实际的设备。这将有助于开发和测试需要地理定位的应用程序

此插件的PluginLoader类当前如下所示:

namespace Pidac.MvvmCross.Plugins.Location
{
    public class PluginLoader : IMvxConfigurablePluginLoader
    {
        private bool _loaded;
        public static readonly PluginLoader Instance = new PluginLoader();

        public void EnsureLoaded()
        {
            if (_loaded)
                return;

            _loaded = true;


            var locationWatcher = new MockGeoLocationWatcher();

            var data = @"<?xml version='1.0' encoding='utf-8'?>
<WindowsPhoneEmulator xmlns='http://schemas.microsoft.com/WindowsPhoneEmulator/2009/08/SensorData'>
    <SensorData>
        <Header version='1' />
        <GpsData latitude='48.619934106826' longitude='-84.5247359841114' />
        <GpsData latitude='48.6852544862377' longitude='-83.9864059059864' />
        <GpsData latitude='48.8445703681025' longitude='-83.7337203591114' />
        <GpsData latitude='48.8662561090809' longitude='-83.2393355934864' />
        <GpsData latitude='49.0825970371386' longitude='-83.0415816872364' />
        <GpsData latitude='49.2621642999055' longitude='-82.7229781716114' />
        <GpsData latitude='49.2621642999055' longitude='-82.6021285622364' />
        <GpsData latitude='49.2047736379815' longitude='-82.3054977028614' />
    </SensorData>
</WindowsPhoneEmulator>";

            locationWatcher.SensorLocationData = data;
            Mvx.RegisterSingleton(typeof(IMvxGeoLocationWatcher), locationWatcher);
        }

        public void Configure(IMvxPluginConfiguration configuration)
        {

        }
    }

    public class MockLocationWatcherConfiguration : IMvxPluginConfiguration
    {
        public static readonly MockLocationWatcherConfiguration Default = new MockLocationWatcherConfiguration();

        // ideally, we should use this property to point to a file or string containing location data
        // this should be configurable outside of code base.
        public string SensorLocationData { get; set; }
    }
}
名称空间Pidac.MvvmCross.Plugins.Location
{
公共类插件加载程序:IMvxConfigurablePluginLoader
{
私家车满载;
公共静态只读PluginLoader实例=新PluginLoader();
重新加载的公共空间()
{
如果(_已加载)
返回;
_加载=真;
var locationWatcher=new MockGeoLocationWatcher();
变量数据=@“
";
locationWatcher.SensorLocationData=数据;
Mvx.RegisterSingleton(类型为(IMvxGeoLocationWatcher),locationWatcher);
}
公共无效配置(IMvxPluginConfiguration配置)
{
}
}
公共类MockLocationWatcherConfiguration:IMvxPluginConfiguration
{
公共静态只读MockLocationWatcherConfiguration默认值=新建MockLocationWatcherConfiguration();
//理想情况下,我们应该使用此属性指向包含位置数据的文件或字符串
//这应该在代码库之外进行配置。
公共字符串SensorLocationData{get;set;}
}
}
我想通过MockLocationWatcherConfiguration实例将传感器数据(当前硬编码到名为“data”的变量中)传递,但在调用IMvxConfigurablePluginLoader.configuration(配置)之前,不知道MvvmCross框架希望在何处加载此插件的配置。理想情况下,我应该通过配置来指定这一点

我查看了,但仍然无法确定在IMvxConfigurablePluginLoader.Configure中尝试强制转换之前从何处检索配置

任何想法或建议都将不胜感激


TIA。

这在维基草稿页面中有介绍-请参阅“编写可配置插件”

在维基中应该更仔细一些。再次感谢。链接已断开,我找到了一个存档链接: