What's the difference between AddConcreteType and TheDefaultIsConcreteType in StructureMap?

岁酱吖の 提交于 2019-12-06 12:33:40
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.

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