Using Prism with Ninject

江枫思渺然 提交于 2019-12-04 09:28:11

问题


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..

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.

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

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?


回答1:


Michael Hart implemented the necessary bits for Ninject in Prism"

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.




回答2:


I have just created a github project that used Ninject 2.0 and Prism 4.0 that should meet the need of anyone that want to swap unity or MEF for Ninject

Site is here: Prism Ninject Extension



来源:https://stackoverflow.com/questions/2621248/using-prism-with-ninject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!