是什么在StructureMap AddConcreteType和TheDefaultIsConcreteType之间的区别? [英] What's the difference between AddConcreteType and TheDefaultIsConcreteType in StructureMap?

查看:157
本文介绍了是什么在StructureMap AddConcreteType和TheDefaultIsConcreteType之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设立StructureMap,它好像一切我想做的事情有两种方法可以做到这一点,这是我不清楚的区别是它们之间有什么。例如,什么是这两条线之间的区别:

<$p$p><$c$c>StructureMapConfiguration.ForRequestedType<IConsumer>().AddConcreteType<Consumer>(); StructureMapConfiguration.ForRequestedType<IConsumer>().TheDefaultIsConcreteType<Consumer>();

同样,有什么用AddInstanceOf之间的区别ForRequestedType?

解决方案

<$p$p><$c$c>StructureMapConfiguration.ForRequestedType<IConsumer>().AddConcreteType<Consumer>();

此方法将增加消费者类型作为插入类型IConsumer。如果没有其他的插入类型IConsumer,那么这种类型的将是默认类型返回IConsumer的一个实例被请求。否则,你将需要通过具体的键(默认情况下是该类型的程序集限定名称),以获得该实例。

<$p$p><$c$c>StructureMapConfiguration.ForRequestedType<IConsumer>().TheDefaultIsConcreteType<Consumer>();

这的工作原理类似于AddConcreteType除了这也使得类型的默认类型。如果对于一个IConsumer一个请求未指定一个具体键时,这是将要返回的类型

至于AddInstanceOf和ForRequestedType,允许你提供一个委托将处理创建指定类型的实例AddInstance之间的区别。 ForRequestedType给你CreatePluginFamilyEx pression一个实例(或GenericFamilyEx pression在ForRequestedType(T型)的情况下),让您在流畅地配置实例。

I'm setting up StructureMap and it seems like everything I want to do there are two ways to do it and it's unclear to me what the difference is between them. For instance, what's the difference between these two lines:

StructureMapConfiguration.ForRequestedType<IConsumer>().AddConcreteType<Consumer>();

StructureMapConfiguration.ForRequestedType<IConsumer>().TheDefaultIsConcreteType<Consumer>();

Similarly, what's the difference between using AddInstanceOf and ForRequestedType?

解决方案

StructureMapConfiguration.ForRequestedType<IConsumer>().AddConcreteType<Consumer>();

This method will add the Consumer type as a plugged type for IConsumer. If there are no other plugged types for IConsumer, then this type will be the default type returned an instance of IConsumer is requested. Otherwise, you will need to get this instance by using the concrete key (which is the assembly qualified name of the type by default).

StructureMapConfiguration.ForRequestedType<IConsumer>().TheDefaultIsConcreteType<Consumer>();

This works similar to AddConcreteType except that it also makes the type the default type. If a request for an IConsumer does not specify a concrete key, this is the type that will be returned.

As for the difference between AddInstanceOf and ForRequestedType, AddInstance of allows you to supply a delegate that will handle creating an instance of the specified type. ForRequestedType gives you an instance of CreatePluginFamilyExpression (or a GenericFamilyExpression in the case of ForRequestedType(Type t)) that allows you to configure an instance in a fluent manner.

这篇关于是什么在StructureMap AddConcreteType和TheDefaultIsConcreteType之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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