c# - MvvmCross,如何在另一个程序集中注册Service?

标签 c# android xamarin inversion-of-control mvvmcross

我在 PCL 中有一个名为 MyProject.Core 的“核心”项目,它具有:

     public interface IPhotoService

然后,我创建一个名为 MyProject.Core.Android 的 Android 类库项目,并添加来自 nuget 的 MvvmCross Core 的引用。现在,通过这样做,我知道我的 Android 类库没有“setup.cs”。

MyProject.Core.Android中,我希望服务(特定于android)如下:

    public class PhotoService : IPhotoService

在我的 Android UI 项目中,我的 Setup.cs 包含以下内容:

    public override void Initialize()
    {
        CreatableTypes()
            .EndingWith("Service")
            .AsInterfaces()
            .RegisterAsLazySingleton();
    }

如果我的 PhotoService 存在于没有 Setup.cs 的程序集 MyProject.Core.Android 中,我该如何注册它???

最佳答案

来自https://github.com/MvvmCross/MvvmCross/wiki/Service-Location-and-Inversion-of-Control :

And you can also, of course, use the same type of registration logic on assemblies other than Core - e.g.:

   typeof(Reusable.Helpers.MyHelper).Assembly.CreatableTypes()
       .EndingWith("Helper")
       .AsInterfaces()
       .RegisterAsDynamic();

关于c# - MvvmCross,如何在另一个程序集中注册Service?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31197455/

相关文章:

c# - 如何从非常大的列表中按索引有效地删除元素?

android - 判断是否触发 ShareActionProvider

ios - IBOutletCollection 与 Xamarin 可能吗?

xamarin - MvvmCross CreateBindingSet 的预期用途

c# - 如何将对象序列化为xml?

c# - 如何获取 Azure Active Directory 登录用户的密码策略

c# - 比较数组 LINQ

android - 混淆 Android 测试项目以及项目(在发布和混淆版本上运行测试)

android - 无法解析符号 'AppCompatActivity'

c# - 如何将属性绑定(bind)到 MAUI 中的 View 模型?