我有两个xUnit测试类,派生自MvxIoCSupportingTest。 运行我的单元测试我收到错误消息:
Cirrious.CrossCore.Exceptions.MvxException : You should only initialize MvxBindingSingletonCache once
有没有办法明确地将IoC实例化为符号?
答案 0 :(得分:1)
使用此类而不是MvxIoCSupportingTest
using MvvmCross.Core;
using MvvmCross.Core.Platform;
using MvvmCross.Platform.IoC;
using MvvmCross.Platform.Platform;
namespace MvvmCross.Test.Core
{
public class BaseMvvmCrossTest
{
static BaseMvvmCrossTest()
{
if (MvxSimpleIoCContainer.Instance == null)
{
MvxSingletonCache.Initialize();
MvxSimpleIoCContainer.Initialize();
MvxSimpleIoCContainer.Instance.RegisterSingleton(MvxSimpleIoCContainer.Instance);
MvxSimpleIoCContainer.Instance.RegisterSingleton<IMvxTrace>(new TestTrace());
MvxSimpleIoCContainer.Instance.RegisterSingleton<IMvxSettings>(new MvxSettings());
MvxTrace.Initialize();
}
}
}
}