I am trying to migrate some code from an old Windows 8.1 app that I had developed using Prism/Unity to a new UWP app using Template 10 and Unity. I have seen in the documentation for Template 10 here that you can override
the ResolveForPage
method.
In my old Windows 8.1 app, there is a Resolve
method in Prism that I would override
like this:
protected override object Resolve(Type type)
{
return Container.Resolve(type);
}
The signature for the Template 10 method is
public override INavigable ResolveForPage(Page page, NavigationService navigationService)
so I am not exactly sure how to convert this. I have registered my repository in OnInitializeAsync
in my App.xaml.cs
, like so:
Container.RegisterType<IPayeesRepository, PayeesRepository>(new ContainerControlledLifetimeManager());
Where Container
is a UnityContainer
instance. My problem is that when I try to inject the dependency on another page, I get a NullReferenceException
because _payeesRepository
is null
. It seems to me like the constructor with the dependency injection is not being called, and if I remove the default constructor then I get an error. Has anyone gotten Unity to work with Template 10 that may have any suggestions what I may be missing?
I also tried using the Dependency
attribute like so:
[Dependency]
private IPayeesRepository _payeesRepository { get; set; }
But that doesn't work either. It seems like the IPayeesRepository
is just not being instantiated, but I'm not exactly sure. In my Windows 8.1 app, it is never explicitly instantiated, so I have a feeling it has something to do with not overriding the Resolve
method.