简体   繁体   English

CompositionContainer.ComposeExportedValue方法到底能做什么?

[英]what exactly does CompositionContainer.ComposeExportedValue method do?

Does the CompositionContainer.ComposeExportedValue method take an object and make the object's export method available? CompositionContainer.ComposeExportedValue方法是否可以使用对象并使该对象的导出方法可用? I am kind of confused what this method does. 我对这种方法的功能感到困惑。 All I know is that this method regsiters object with the container. 我所知道的是,此方法注册者将容器作为对象。 How does it register objects with the container? 它如何在容器中注册对象? Does this method majically somehow make an object's export methods, or an object that has the export attribute available for other classess? 这个方法是否在某种程度上可以使对象的导出方法或具有export属性可用于其他类的对象?

AFAIK the AttributedModelServices.ComposeExportedValue<T> extension method for CompositionContainer registers the given object as a part satisfying contract T . AFAIK CompositionContainerAttributedModelServices.ComposeExportedValue<T>扩展方法将给定对象注册为满足合同T的一部分。 This means that the object will indeed be used to compose other objects which import T . 这意味着该对象确实将用于组成其他导入T对象。

Perhaps more important is what it doesn't do : 也许更重要的是它不做的事情

  • It doesn't try to set any properties with Import attributes. 它不会尝试使用Import属性设置任何属性。 You can do that with AttributedModelServices.ComposeParts . 您可以使用AttributedModelServices.ComposeParts做到这一点。
  • It doesn't transfer ownership of the object to the container. 它不会将对象的所有权转移到容器。 If the object is IDisposable , it will not be disposed when the container is disposed. 如果对象是IDisposable ,则在处理容器时将不会处理该对象。

In general you should avoid these methods. 通常,您应避免使用这些方法。 Typically you would just add the necessary attributes to your class and add it to the container via a AssemblyCatalog . 通常,您只需将必要的属性添加到类中,然后通过AssemblyCatalog将其添加到容器中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM