【发布时间】:2018-04-23 15:29:57
【问题描述】:
我尝试在 xamarin 表单中使用 facebook 登录,但我在应用程序加载时在构造函数中有 Excpetion 这是我的代码
private readonly INavigationService _navigateService;
private readonly IFacebookManager _facebookManager;
private readonly IPageDialogService _dialogService;
在构造函数
中public LoginPageViewModel(INavigationService navigationService, IPageDialogService dialogService , IFacebookManager facebookManager)
{
_dialogService = dialogService;
_facebookManager = facebookManager;
_navigateService = navigationService;
IsLogedIn = false;
}
但我遇到了这个异常,我不知道为什么
Unity.Exceptions.ResolutionFailedException: Resolution of the dependency failed, type = 'System.Object', name = 'LoginPage'.
Exception occurred while: Calling constructor LGMobileApp.Views.LoginPage().
Exception is: ResolutionFailedException - Resolution of the dependency failed, type = 'LGMobileApp.ViewModels.LoginPageViewModel', name = '(none)'.
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, LGMobileApp.Helpers.IFacebookManager, is an interface and cannot be constructed. Are you missing a type mapping?
-----------------------------------------------
At the time of the exception, the container was:
Resolving LGMobileApp.ViewModels.LoginPageViewModel,(none)
Resolving parameter 'facebookManager' of constructor LGMobileApp.ViewModels.LoginPageViewModel(Prism.Navigation.INavigationService navigationService, Prism.Services.IPageDialogService dialogService, LGMobileApp.Helpers.IFacebookManager facebookManager)
Resolving LGMobileApp.Helpers.IFacebookManager,(none)
-----------------------------------------------
At the time of the exception, the container was:
Resolving LGMobileApp.Views.LoginPage,LoginPage (mapped from System.Object, LoginPage)
Resolving LGMobileApp.Views.LoginPage,LoginPage
Calling constructor LGMobileApp.Views.LoginPage()
在我的 app.cs 中
protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
containerRegistry.RegisterForNavigation<LoginPage>();
}
有什么帮助吗?
【问题讨论】:
-
您是否在 Unity 容器中设置了
IFacebookManager? -
我该怎么做?
-
好吧,那是你的代码,你不知道你的 DI 系统是如何工作的吗?比如
IPageDialogService这个接口就会注册在那里,试试看。 -
感谢 @DavidG 重播我使用 prism.unity 但这是我第一次遇到这个问题 .. 在我的 app.cs 中我总是只注册导航
-
@DavidG 我编辑了这个问题,我认为它与我的 di 中的容器有关我如何注册这个接口
标签: c# xamarin.forms prism