Reputation: 223
I have a few question related to Xamarin Prism dependency, could you please help me?
In the App.xmal.cs I've registered a service called UserService
protected override void RegisterTypes()
{
Container.RegisterType<IUserService, UserService>(); ....
And this works perfectly via ViewModels as in numerous examples on the Internet. But in my UC on application load I need to call a method from UserService to check some login details.
At the moment on OnInitialized I redirect a user to some dummy page in order to use dependency instanced UserService.
Is it possible to get an instance of UserService directly in the App.xaml.cs via Prism dependency injection (outside of a model)
Upvotes: 0
Views: 768
Reputation: 10883
Rather easy:
Container.Resolve<IUserservice>();
...not before the registration, of course... ...and not nice, too, try not to use the container directly, but in this case, it's your only option.
Upvotes: 2