C# Xamarin表单向Unity for View模型构造函数注册客户服务
我试图在导航到ViewModel时将服务注入其中。尽管我在Brian Lagunas的博客上看到了参考资料、示例代码等,但有些地方似乎并不正确 在我的App.cs中给出C# Xamarin表单向Unity for View模型构造函数注册客户服务,c#,unity-container,xamarin.forms,prism,C#,Unity Container,Xamarin.forms,Prism,我试图在导航到ViewModel时将服务注入其中。尽管我在Brian Lagunas的博客上看到了参考资料、示例代码等,但有些地方似乎并不正确 在我的App.cs中给出 public class App : PrismApplication { protected override void OnInitialized () { NavigationService.NavigateAsync ("SignInPage", animated: false);
public class App : PrismApplication
{
protected override void OnInitialized ()
{
NavigationService.NavigateAsync ("SignInPage", animated: false);
}
protected override void RegisterTypes ()
{
Container.RegisterTypeForNavigation<SignInPage>();
Container.RegisterType<IUserAuthentication, UserAuthenticationService>();
}
private INavigationService _navigationService;
private IUserAuthentication _userAuthenticationService;
public SignInPageViewModel(INavigationService navigationService, IUserAuthentication userAuthenticationService)
{
_navigationService = navigationService;
_userAuthenticationService = userAuthenticationService;
}
Container.RegisterType
似乎不接受泛型。我看到的所有关于Unity的例子似乎都支持它,但我得到了以下错误
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 v6.1.0-pre5
- 棱镜芯6.1.0
- Xamarin.表格2.3.0.46-pre3
- 统一4.0.1
Microsoft.Practices.Unity
命名空间中。要使用它,请显式调用它
Microsoft.Practices.Unity.UnityContainerExtensions.RegisterType<ISomething, SomeService>( Container );
RegisterType
的通用版本是一种扩展方法,位于Microsoft.Practices.Unity
命名空间中。要使用它,请显式调用它
Microsoft.Practices.Unity.UnityContainerExtensions.RegisterType<ISomething, SomeService>( Container );
花点时间阅读。目前看来,这个答案几乎毫无用处。花点时间阅读。就目前而言,这个答案几乎毫无用处!非常感谢。对.NET来说还是新鲜事。我(错误地)认为Prism的Unity扩展将把Unity的其余部分拉进来。有时候,找到我想要的语句是最具挑战性的一点!非常感谢。对.NET来说还是新鲜事。我(错误地)认为Prism的Unity扩展将把Unity的其余部分拉进来。有时候,找到我想要的语句是最具挑战性的一点。