Prism.Container.Extensions icon indicating copy to clipboard operation
Prism.Container.Extensions copied to clipboard

Losing RegionAdapter mappings using Microsoft.DI extensions...

Open horseyhorsey opened this issue 3 years ago • 10 comments

We can get constructor injection working with the following.

protected override IContainerExtension CreateContainerExtension() => PrismContainerExtension.Init();

protected override void RegisterTypes(IContainerRegistry containerRegistry)
{
    containerRegistry = containerRegistry.RegisterServices(svc =>
    {
        MyApplication.DependencyInjection.AddApplication(svc);
    });
}

The IRegionAdapter for the type System.Windows.Controls.ContentControl is not registered

Prism.Regions.UpdateRegionsException: 'An exception occurred while trying to create region objects. 
    - The most likely causing exception was: 'System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> Prism.Regions.Behaviors.RegionCreationException: An exception occurred while creating a region with name 'SidePanelRegion'. The exception was: System.Collections.Generic.KeyNotFoundException: The IRegionAdapter for the type System.Windows.Controls.ContentControl is not registered in the region adapter mappings. You can register an IRegionAdapter for this control by overriding the ConfigureRegionAdapterMappings method in the bootstrapper.
   at Prism.Regions.RegionAdapterMappings.GetMapping(Type controlType)
   at Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName). 
 ---> System.Collections.Generic.KeyNotFoundException: The IRegionAdapter for the type System.Windows.Controls.ContentControl is not registered in the region adapter mappings. You can register an IRegionAdapter for this control by overriding the ConfigureRegionAdapterMappings method in the bootstrapper.
   at Prism.Regions.RegionAdapterMappings.GetMapping(Type controlType)
   at Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
   --- End of inner exception stack trace ---
   at Prism.Regions.Behaviors.DelayedRegionCreationBehavior.CreateRegion(DependencyObject targetElement, String regionName)
   at Prism.Regions.Behaviors.DelayedRegionCreationBehavior.TryCreateRegion()
   at Prism.Regions.Behaviors.DelayedRegionCreationBehavior.OnUpdatingRegions(Object sender, EventArgs e)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at Prism.Events.WeakDelegatesManager.Raise(Object[] args)
   at Prism.Regions.RegionManager.UpdateRegions()'.
    But also check the InnerExceptions for more detail or call .GetRootException(). '

After overriding the ConfigureRegionAdapterMappings we can see the mappings there after invoking the base method.

Not sure where these get lost? The app works as it should using Unity.

horseyhorsey avatar Dec 27 '20 22:12 horseyhorsey