dansiegel/Prism.Container.Extensions

How to use IExtendedContainerRegistry

budul100 opened this issue · 3 comments

I have created a very simple DryIoc app using the Prism.DryIoc and the Prism.DryIoc.Extensions nuget packages:

using _TestApp.Views;
using Prism.Ioc;
using System.Windows;

namespace _TestApp
{
    public partial class App
    {
        protected override Window CreateShell()
        {
            return Container.Resolve<MainWindow>();
        }

        protected override void RegisterTypes(IContainerRegistry containerRegistry)
        {
            containerRegistry.RegisterSingleton<ITest, Test>();
            containerRegistry.RegisterDelegate<ITest>(c => c.Resolve<ITest>().Child);
        }
    }

    public class Child : IChild
    {
        public string Name { get; set; }
    }

    public class Test : ITest
    {
        public IChild Child { get; set; }
    }

    public interface IChild
    {
        string Name { get; set; }
    }

    public interface ITest
    {
        IChild Child { get; set; }
    }
}

But it fails at containerRegistry.RegisterDelegate<ITest>(c => c.Resolve<ITest>().Child);. Presumably the reason is that the extension methode fails to resolve an IExtendedContainerRegistry from IContainerRegistry.

So I wonder, how can I get an IExtendedContainerRegistry in a Prism.DryIoc app? Do I miss something?

Hello @budul100 as you can see in documentation https://prismplugins.com/ ContainerExtension usage is just based on Prism.Forms.Extended + Prism.[Your prefered Container Provider].Extensions any other Prism package must be uninstalled. Once you have done this everything should works.

Thank you for your answer. I'll try that.

@budul100 it looks like you're trying to build a WPF app... I never provided an Extended version of WPF because the container requires a bit more integration... if you look at Prism.DryIoc.Wpf on the Prism 7.2 tag it should give you an idea some of the plugins you need to do for your container and Prism.DryIoc.Extensions...

Alternatively you might look at using Prism 8 which actually adopted nearly all of the benefits of the IExtendedContainerRegistry.