开发者

How to use PRISM 4 in already developed silverlight 4 project using MVVM pattern?

I am new to Prism pattern. We have developed 3 Silverlight 4 projects using MVVM pattern. Now we want to combine these 3 projects into a single project. I want to use Prism 4 to do this.

I have to pass values to constructor of a viewmodel class from another viewmodel and communicate with other viewmodel class methods.

Please tell me the 开发者_如何转开发approach to do this using Prism.


Long story short :

  • Prism is not a pattern, it's a library.

  • Lookup a term : "BootStrapper" and registering types and instances within a "container" aka the UnityContainer in Prism. This is typically done in the Bootstrapper's overriden ConfigureContainer method. There you "tell" the container what are the types that are going to be known to it from now on.

  • Later you can re-use those already defined (and often instantiated) types when "resolving" other types. The container is smart enough to resolve all known dependencies that you pass through a ViewModel's constructor.

I'm sorry, but I'm currently unable to provide any examples b/c I'm travelling.


I have done this using MEF with Prism. I'm sure you could do it with Unity as well, but I have not used that before so can't tell you how it's done. The Prism Quickstarts on Modularity and EventAggregation is a good place to start.

Using MEF, I would pass values to the ViewModel via the constructor using the [ImportingConstructor] attribute, and use the EventAggregator for passing other data between loosely coupled ViewModels.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜