質問

I am developing an MVVM WPF application using the MVVMlight toolkit.

It comes with the SimpleIoc container mainly for design time / runtime separation (correct me if I'm wrong).

My question is does it do anything else other than that?

I need IOC for other parts of the program and very likely I will use something like Ninject.

Also very likely to make it extensible I am going to use MEF.

Then there will be 3 independent IOC things (SimpleIoc from mvvmlight, Ninject, and MEF) in the application. Is this feasible and necessary?

Can one do the work of the other two, or I really need them three to cover different areas.

Any best practice suggestions?

Thanks in advance.

役に立ちましたか?

解決 2

In your case I would use Prism. It is much more mature than MVVM light. Yes it is also bigger so if you will not be making modular app you can take only Unity IOC which is probably one of the best containers out there. If you more than one it depends on the approach to the architectural problems you take. Basically one container should be more than enough.

他のヒント

Another vote for Prism. For containers within Prism, I tend to just pick one IoC container- and I usually choose MEF. It works great for all the things they say it does (discoverability, plugin architecture, recomposition, etc.). I use it to wire my apps up, tying the viewmodels to views, and letting region navigation instantiate things for me.

One area where Unity is better is dynamic object creation- you can request a specific type of object from the unity container and get back an object with the dependencies satisfied. But there's a nice little tool that Glen Block made called the CompositionInitializer that allows you to satisfy imports for -any- class you create using MEF. Blog posts here and here describing how to use it as well as where to get it.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top