CompositionContainer.ComposeExportedValue 方法到底做什么?
CompositionContainer.ComposeExportedValue 方法是否接受一个对象并使该对象的导出方法可用?我有点困惑这个方法的作用。我所知道的是这个方法将对象注册到容器中。它如何向容器注册对象?此方法是否以某种方式使对象的导出方法或具有导出属性的对象可用于其他类?
Does the CompositionContainer.ComposeExportedValue method take an object and make the object's export method available? 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我所知
AttributedModelServices.ComposeExportedValue
CompositionContainer
的扩展方法 将给定对象注册为满足契约T
的一部分。这意味着该对象确实将用于组成导入T
的其他对象。也许更重要的是它不做:
AttributedModelServices.ComposeParts 来完成此操作
。IDisposable
,则在处置容器时不会处置该对象。一般来说,您应该避免使用这些方法。通常,您只需向类添加必要的属性,然后通过
AssemblyCatalog
将其添加到容器中。AFAIK the
AttributedModelServices.ComposeExportedValue<T>
extension method forCompositionContainer
registers the given object as a part satisfying contractT
. This means that the object will indeed be used to compose other objects which importT
.Perhaps more important is what it doesn't do:
AttributedModelServices.ComposeParts
.IDisposable
, it will not be disposed when the container is disposed.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
.