依赖关系的解决 - Xamarin - Unity
Resolution of the dependency - Xamarin - Unity
该项目是 Unity doc 的副本,但它引发了一个我无法理解的错误
错误是:
Unhandled Exception:
Unity.Exceptions.ResolutionFailedException: Resolution of the
dependency failed, type = 'System.Object', name = 'MainPage'.
Exception occurred while: Calling constructor
SecondPrims.Views.MainPage(). Exception is: ResolutionFailedException
- Resolution of the dependency failed, type = 'SecondPrims.ViewModels.MainPageViewModel', name = '(none)'. Exception
occurred while: while resolving. Exception is:
InvalidOperationException - The current type, ITextToSpeech, is an
interface and cannot be constructed. Are you missing a type mapping?
----------------------------------------------- At the time of the exception, the container was: Resolving
SecondPrims.ViewModels.MainPageViewModel,(none) Resolving parameter
'textToSpeech' of constructor
SecondPrims.ViewModels.MainPageViewModel(ITextToSpeech textToSpeech)
Resolving ITextToSpeech,(none)
----------------------------------------------- At the time of the exception, the container was: Resolving
SecondPrims.Views.MainPage,MainPage (mapped from System.Object,
MainPage)
Resolving SecondPrims.Views.MainPage,MainPage
Calling constructor SecondPrims.Views.MainPage() occurred
项目文件:
http://www.mediafire.com/file/fs656jowkiy2bd9/SecondPrims.zip
您是否正确添加了依赖项?
containerRegistry.RegisterForNavigation<MainPage>();
containerRegistry.Register<ITextToSpeech, TextToSpeech>();
答案是因为在各个平台注册了ITextToSpeech接口
Prism 7 changed this behavior as it is actually an anti-pattern to
rely on a secondary container. You simply need to register your
TextToSpeech service in the IPlatformInitializer like:
public class iOSInitializer : IPlatformInitializer
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.Register<ITextToSpeech, TextToSpeech_iOS>();
}
}
该项目是 Unity doc 的副本,但它引发了一个我无法理解的错误
错误是:
Unhandled Exception:
Unity.Exceptions.ResolutionFailedException: Resolution of the dependency failed, type = 'System.Object', name = 'MainPage'. Exception occurred while: Calling constructor SecondPrims.Views.MainPage(). Exception is: ResolutionFailedException - Resolution of the dependency failed, type = 'SecondPrims.ViewModels.MainPageViewModel', name = '(none)'. Exception occurred while: while resolving. Exception is: InvalidOperationException - The current type, ITextToSpeech, is an interface and cannot be constructed. Are you missing a type mapping? ----------------------------------------------- At the time of the exception, the container was: Resolving SecondPrims.ViewModels.MainPageViewModel,(none) Resolving parameter 'textToSpeech' of constructor SecondPrims.ViewModels.MainPageViewModel(ITextToSpeech textToSpeech) Resolving ITextToSpeech,(none)
----------------------------------------------- At the time of the exception, the container was: Resolving SecondPrims.Views.MainPage,MainPage (mapped from System.Object, MainPage) Resolving SecondPrims.Views.MainPage,MainPage Calling constructor SecondPrims.Views.MainPage() occurred
项目文件: http://www.mediafire.com/file/fs656jowkiy2bd9/SecondPrims.zip
您是否正确添加了依赖项?
containerRegistry.RegisterForNavigation<MainPage>();
containerRegistry.Register<ITextToSpeech, TextToSpeech>();
答案是因为在各个平台注册了ITextToSpeech接口
Prism 7 changed this behavior as it is actually an anti-pattern to rely on a secondary container. You simply need to register your TextToSpeech service in the IPlatformInitializer like:
public class iOSInitializer : IPlatformInitializer
{
public void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.Register<ITextToSpeech, TextToSpeech_iOS>();
}
}