0

我想在我的 ui 中使用温莎城堡作为 mvvm 的 IoC 和棱镜。

所以我用 Windsor 引导程序注册了我所有的课程:

            Container.Register(
            Classes.FromThisAssembly()
                .Pick()
                .WithServiceAllInterfaces()
                .WithServiceSelf()
                .WithServiceBase()
                .LifestyleTransient());

然后我想导航到我的视图:

RegionManager.RequestNavigate(RegionNames.SideBarRegion, "PreEventNavigationView");

然后抛出异常。来自堆栈跟踪的重要信息是:

{"Activation error occurred while trying to get instance of type Object, key \"PreEventNavigationView\""}

{"Requested component named 'PreEventNavigationView' was not found in the container. Did you forget to register it?\r\nThere are 55 other components supporting requested service 'System.Object'. Were you looking for any of them?"}

我认为我需要注册我的组件,system.object但这也无济于事。有了这个我的用户界面不起作用,我得到了一些奇怪的行为:

        Container.Register(
            Component.For<PreEventNavigationView,System.Object>()
                .ImplementedBy<PreEventNavigationView>().LifestyleSingleton());

我想我在某处读到我不应该在温莎城堡注册对象。如何在温莎城堡中正确使用 Prism Navigation,还是不可能?

4

1 回答 1

0

问题是这部分:

        Container.Register(
        Classes.FromThisAssembly()
            .Pick()
            .WithServiceAllInterfaces()
            .WithServiceSelf()
            .WithServiceBase()
            .LifestyleTransient());

我只用完整的命名空间注册了它们(或者默认情况下是 windsor),而不仅仅是类名。所以有2个灵魂:

RegionManager.RequestNavigate(RegionNames.SideBarRegion, "Full.NameSpace.PreEventNavigationView");

或者

        Container.Register(
        Classes.FromThisAssembly()
            .Pick()
            .Configure(registration => registration.Named(registration.Implementation.Name))
            .WithServiceAllInterfaces()
            .WithServiceSelf()
            .WithServiceBase()
            .LifestyleTransient());
于 2015-10-02T09:11:11.413 回答