使用棱镜与Ninject [英] Using Prism with Ninject

查看:202
本文介绍了使用棱镜与Ninject的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有人在那里使用棱镜框架与Ninject,而不是统一?我需要一些功能,统一不配套的是,我已经决定了IoC容器切换到Ninject。我挣扎了一下与替换虽然..

Is anyone out there using the Prism framework with Ninject instead of Unity? I need some functionality Unity isn't supporting yet, and I've decided to switch the IoC container to Ninject. I'm struggling a bit with the replace though..

我需要从棱镜使用的是EventAggregator和RegionManager。我所看到的<一个href="http://$c$c.google.com/p/ninject-contrib/source/browse/trunk/CompositeWpf/NinjectContrib.CompositeWpf/">this品尝实际执行替换,但这是棱镜的旧版本写的,几个班似乎如此,我结束了所有的迷茫寻找做一些努力,试图改写后已经改变等等。

What I need to use from Prism is the EventAggregator and the RegionManager. I have seen this sample that actually does the replace, but this is written for an older version of Prism, and several of the classes seems to have changed etc. So I ended up all confused after looking doing some effort in trying to rewrite it.

所以 - 我的问题基本上是:如何替换团结与Ninject

So - my question is basically: How can I replace Unity with Ninject?

什么是必要的步骤?起初我以为我可以写,创建和配置Ninject容器,并使用此解决所有其它对象一个简单的引导程序。我绑定IEventAggregator到EventAggregator和IRegionManager到RegionManager,但创建的外壳和RegionManager.CreateRegion被调用时,它会失败。问题是,它似乎是我需要,因为它无法在这条线的地方设置一个服务定位:

What are the necessary steps? Initially I assumed I could write a simple bootstrapper that creates and configures a Ninject container and uses this to resolve all other objects. I bind IEventAggregator to EventAggregator and IRegionManager to RegionManager, but it fails when creating the Shell and the RegionManager.CreateRegion is called. Problem is that it seems like I need to set a ServiceLocator somewhere as it fails on this line:

IServiceLocator locator = ServiceLocator.Current;

任何想法和建议,一路上?

Any ideas and tips along the way?

推荐答案

迈克尔·哈特的实施了必要的位了解Ninject在棱镜

Michael Hart implemented the necessary bits for Ninject in Prism"

您只需要实现自己的NinjectBoostrapper和IServiceLocator的使用Ninject的实现。在code中的链接做这一切跑腿给你。

You need only implement your own "NinjectBoostrapper" and an implementation of IServiceLocator that uses Ninject. The code in the link does all of this legwork for you.

这篇关于使用棱镜与Ninject的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆