如何在Prism模块中注册特定于平台的实现?

亚当

我正在尝试在Xamarin Forms应用程序中创建Prism模块。我的模块包含特定于平台的代码和用于该接口的视图模型。例如:

ThingModule (PCL)
 ThingModule
   + Initialize()
 IThing
 ThingView
 ThingViewModel(IThing thing)

ThingModule.Droid (Android)
 AndroidThingImplementation : IThing

ThingModule.iOS (iOS)
 iOSThingImplementation : IThing

我可以在模块的Initialize方法中轻松注册视图以便导航,但是如何在模块(而不是应用程序)中注册特定于平台的实现?

54

您无需在该模块中注册平台详细信息。您可以在特定于平台的实际项目中注册特定于平台的内容。您的模块只需要引用该接口即可,仅此而已。您可以使用IPlatformInitializer来执行此操作。在此处查看示例:

Android:https//github.com/PrismLibrary/Prism/blob/master/Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld.Droid/MainActivity.cs#L28

[Activity(Label = "HelloWorld", Icon = "@drawable/icon", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.tabs;
        ToolbarResource = Resource.Layout.toolbar;

        base.OnCreate(bundle);

        global::Xamarin.Forms.Forms.Init(this, bundle);
        LoadApplication(new App(new AndroidInitializer()));
    }
}

public class AndroidInitializer : IPlatformInitializer
{
    public void RegisterTypes(IUnityContainer container)
    {

    }
}

XF项目:https : //github.com/PrismLibrary/Prism/blob/master/Sandbox/Xamarin/HelloWorld/HelloWorld/HelloWorld/App.cs#L15

public class App : PrismApplication
{
    public App(IPlatformInitializer initializer = null) : base(initializer) { }
    ...
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Spring Boot中注册ServletContextListener

如何在vuex中注册多个插件?

如何在Go中处理平台特定的模块?

如何在Flutter / Dart中导入特定于平台的依赖项?(结合使用Android / iOS的Web)

如何在Asp.Net Core中注册同一接口的多个实现?

如何在Spring Test中注册ApplicationEnvironmentPreparedEvent

如何在MVVM Light的SimpleIoc中注册实现多个接口的类?

测试厨房:如何在kitchen.yml中读取特定于平台的属性

如何在autofac中注册Generic接口的所有实现?

Ansible:如何在uri模块中注册变量?

如何在eXist-db中注册RESTXQ模块?

如何在LLVM pass中添加特定于平台的功能定义?

如何在我的R函数中使用特定于平台的软件包

如何在F#中注册AsyncEventingBasicConsumer

如何在Unity中使用Prism在同一实例中注册服务?

如何在模块中调用特定于类的方法

如何在MORYX模块中注册WFC主机工厂?

如何在C ++中注册动态成员

我应该如何在Linux中获取特定于平台的jni标头以进行交叉构建?

如何在配置中注册Autofac模块

NancyFx 仅在代码中注册特定模块

如何在MvvmLight的IoC中注册多个接口实现?

如何在 Minecraft Forge 中注册 ItemBlock?

如何在内核模块中注册用户空间内存区域?

WPF Prism 6.2 (Unity) - 如何在启动模块加载时注册事件

如何在 Ejabberd elixir 模块中注册 IQ 处理程序?

我们如何在 iOS 14 中注册多平台应用程序以接收通知?

ServiceStack IoC/DI:在容器中注册类 - 如何注册所有实现特定接口的类

如何在 asp.net core 中注入特定的实现