我试图在ViewModel导航到时将服务注入。尽管我在Brian Lagunas的博客,示例代码等上看过这方面的参考资料,但似乎并不正确。Xamarin Forms使用Unity注册客户服务以查看模型构造函数
鉴于我App.cs
public class App : PrismApplication
{
protected override void OnInitialized()
{
NavigationService.NavigateAsync ("SignInPage", animated: false);
}
protected override void RegisterTypes()
{
Container.RegisterTypeForNavigation<SignInPage>();
Container.RegisterType<IUserAuthentication, UserAuthenticationService>();
}
}
注:using
报表。IUserAuthentication和UserAuthenticationService命名空间到位。
SignInPageViewModel.cs
private INavigationService _navigationService;
private IUserAuthentication _userAuthenticationService;
public SignInPageViewModel(INavigationService navigationService, IUserAuthentication userAuthenticationService)
{
_navigationService = navigationService;
_userAuthenticationService = userAuthenticationService;
}
Container.RegisterType
似乎并不接受通用的。我见过的所有例子似乎都支持它,但我得到以下错误。
The non-generic method 'IUnityContainer.RegisterType(Type, Type, string, LifetimeManager, params InjectionMember[])' cannot be used with type arguments
这是一个构建错误。
软件包信息
- 使用Prism.Unity.Forms V6.2.0-pre5
- Prism.Forms 6.1.0-pre5
- Prism.Core 6.1.0
- Xamarin.Forms 2.3 .0.46-PRE3
- 统一4.0.1
Gah!谢谢。仍然是.NET新手。我认为(错误地)认为Prism的Unity扩展会将其余的Unity内容拉入。 有时,找到我想要的使用语句是最具挑战性的一点。 – Danomite