I am using Prism 6.3.0 with Autofac.
When I register a type for navigation inside the Initialize() method of a IModule like this:
public class TestModule : IModule
{
public TestModule (ContainerBuilder builder)
{
this.Builder = builder;
}
private ContainerBuilder Builder { get; set; }
public void Initialize()
{
...
this.Builder.RegisterTypeForNavigation<ViewTest>();
}
}
And then try to navigate from another Module like this:
private void NavigateTest()
=>
this.RegionManager.RequestNavigate("MainContentRegion", new Uri("ViewTest", UriKind.Relative), this.Result);
private void Result(NavigationResult obj)
{ // Breakpoint here
}
It fails with the following error:
The requested service 'ViewTest (System.Object)' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.
And StackTrace:
en Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) en Prism.Autofac.AutofacServiceLocatorAdapter.DoGetInstance(Type serviceType, String key) en Microsoft.Practices.ServiceLocation.ServiceLocatorImplBase.GetInstance(Type serviceType, String key) en c:\Projects\CommonServiceLocator\main\Microsoft.Practices.ServiceLocation\ServiceLocatorImplBase.cs:lĂnea 49
But if I register the type in ConfigureContainerBuilder(ContainerBuilder builder), it works fine and I can navigate without problems:
protected override void ConfigureContainerBuilder(ContainerBuilder builder)
{
builder.RegisterTypeForNavigation<ViewTest >();
base.ConfigureContainerBuilder(builder);
}
Is it possible to do the registration in the Module's Initialize() method or does it have to be in ConfigureContainerBuilder()?
Thanks