具有两个核心库的MvvmCross [英] MvvmCross with two core libraries
问题描述
是否可以将两个Core库链接到您的应用程序中?
我想创建一个具有登录和帐户视图模型的Common.Core库.
我想要另一个Domain.Core库,其中包含一些域视图模型.
这些可以用于多个不同的项目.
在我的应用中,我执行一个新的Setup().Initialize().
我的安装程序类重写CreateApp()...
Is it possible to link two Core libraries into your app?
I would like to create one Common.Core library that has login and account view models.
I would like another one Domain.Core library that has some domain view models in it.
These could be used across a couple different projects.
In my app, I do a new Setup().Initialize().
My Setup class overrides CreateApp() ...
public class Setup : MvxPhoneSetup
{
protected override IMvxApplication CreateApp()
{
CreatableTypes().EndingWith("Service").AsInterfaces().RegisterAsLazySingleton();
return new Common.Core.App();
// TODO: can I setup a Domain.Core library here too?
}
}
我已经尝试过这样做...
I have tried doing this ...
CreatableTypes(Assembly.Load("Domain.Core")).EndingWith("Service").AsInterfaces().RegisterAsLazySingleton();
但是当我尝试从那里解析域模型时,我遇到了ReflectionTypeLoadException.
任何人都尝试过这样的事情吗?
but I'm getting a ReflectionTypeLoadException when I try to resolve a domain model from there.
Anyone tried something like this?
谢谢!
推荐答案
是的,使用多个核心"项目应该可以.
Yes, using multiple 'core' projects should work.
出现在Resolve
上的ReflectionTypeLoadException
表明您的第二个Assembly需要另一个不可用的Assembly?通过一个非常简单的第二个核心项目,您是否会遇到相同的问题?您可以获得有关该异常的更多信息吗?这是在哪个平台上发生的?
The ReflectionTypeLoadException
occurring on Resolve
suggests that maybe your second Assembly requires another Assembly that isn't available? Do you get the same problem with a very simple second core project? Can you get any more information about the exception? Which platform is this occurring on?
如果要从多个程序集中加载ViewModel
类型,则可以重写一个Setup方法-MvvmCross中的默认ViewModelLocator从安装程序中列出的程序集中获取ViewModel的列表-请参见
If you want to load ViewModel
types from multiple assemblies, then there is a Setup method you can override - The default ViewModelLocator in MvvmCross gets its list of ViewModels from the assemblies listed in Setup - see MvxSetup.cs
(很抱歉,此列表在ui项目中-应该确实在主核心项目中)
(Sorry this list is in the ui project - should really be in the main core project)
出于跨平台兼容性的考虑,我不建议使用Assembly.Load
-最好使用更静态的方法,例如typeof(Domain.Core.Something).Assembly
For cross-platform compatibility, I don't recommend using Assembly.Load
- better to use a more static method like typeof(Domain.Core.Something).Assembly
在xamarin.android和(特别是)xamarin.ios之类的打包应用程序"平台上工作我不建议使用Assembly.Load
-仅在静态引用了程序集且已经加载了程序集的情况下,这才在iOS平台上工作-这就是插件在iOS上具有特殊引导文件的原因.还要注意,Assembly.Load中使用的名称在不同平台上是不同的-例如,在Android中,必须使用以.dll结尾的文件名-请参见
Working on 'packaged application' platforms like xamarin.android and (especially) xamarin.ios I don't recommend using Assembly.Load
- this will only work on the iOS platforms if the assembly is referenced statically and has already been loaded - that's the reason plugins have a special bootstrap file on iOS. Also be aware that the name used in Assembly.Load is different on different platforms - eg in Android you must use the filename ending in .dll - see MvxAndroidSetup.cs. For other platforms like WP and winRT, then Assembly.Load
may work more conventionally though - although I've personally spent hours/days/weeks swearing at this sort of code in the last year.
这篇关于具有两个核心库的MvvmCross的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!