MVVM光 - 简单的IoC + CommonServiceLocator?试图了解的目的 [英] MVVM Light - Simple IoC + CommonServiceLocator? Trying to understand the purpose

查看:1459
本文介绍了MVVM光 - 简单的IoC + CommonServiceLocator?试图了解的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我知道,CommonServiceLocator是一个中介并列允许你切换出不同的IoC容器,但在看MVVM光的样品code,特别是ViewModelLocator,似乎在某种意义上说,

您注册SimpleIoC作为默认的定位器,但在同一时间,你调用注册的SimpleIoc默认实例。

所以,如果你要撕出SimpleIoC在将来,是不是意味着你需要更新所有的注册要求?

另外一个问题是,有使用温莎城堡,在过去,它的加载类型的支持经由config文件配置它们,会是怎样在Windows 8的情况工作吗?

我仍然试图找到场景的地方使用IoC现在是有道理的?

解决方案

这是不需要更换的getter调用的公共服务定位​​的实现担保(的GetInstance,GetAllInstances等),但他们停在那里。注册是什么使一个IOC容器是唯一的;例如,你提到,与配置文件的一些支持的配置(SimpleIoc做什么不是)。所以,是的,当你与你选择的另一个IOC容器更换SimpleIoc,您通常会更换注册部分。需要注意的是它通常是行,因为这些调用典型地被分组在一个共同的地方,所以他们是相当容易更换。

有关更多信息,请查看 HTTP://commonservicelocator.$c$cplex.com/

请注意,我在加入SimpleIoc到MVVM光的目标不是提供一个全能的IOC容器。事实上,我低头现有的(温莎城堡,StructureMap,团结,等等)。相反,我想提供一个简单的实现,将吸引雏用户在IOC容器的世界。我们的想法是,当它们需要更先进的功能,它们将移动到另一个,更复杂的实施

希望这是有道理的! 洛朗

So I am aware that the CommonServiceLocator is an intermediary tie for allowing you to switch out different IoC containers, but looking at the MVVM Light's sample code, specifically the ViewModelLocator, it seems interesting in the sense that

You register the SimpleIoC as the default locator, but at the same time you call Register on the SimpleIoc default instance.

So if you were going to tear out SimpleIoC in the future, wouldn't it mean you'll need to update all the registration calls?

Another question is, having used Castle Windsor in the past, and it's support for loading types by configuring them via the .config file, how would it work in the Windows 8 scenario?

I'm still trying to find the scenario's where the use of IoC makes sense now?

解决方案

The Common Service Locator implementation guarantees that you do not need to replace the getter calls (GetInstance, GetAllInstances, etc) but they stopped there. Registration is what makes an IOC container unique; for example, as you mention, some support configuration with config files (what SimpleIoc does not). So yes, when you replace SimpleIoc with another IOC container of your choice, you will typically replace the registration part. Note that it is usually OK because these calls are typically grouped in a common place, so they are rather easy to replace.

For more info, check the http://commonservicelocator.codeplex.com/ page.

Note that my goal in adding SimpleIoc to MVVM Light was not to offer an all-powerful IOC container. In fact, I bow to the existing ones (Castle Windsor, StructureMap, Unity, etc). Instead I wanted to provide a simple implementation that will lure unexperienced users in the world of IOC containers. The idea is that, when they need more advanced features, they will move to another, more complex implementation.

Hope this makes sense! Laurent

这篇关于MVVM光 - 简单的IoC + CommonServiceLocator?试图了解的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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