what exactly does CompositionContainer.ComposeExportedValue method do?
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 regs开发者_如何学运维iters 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?
AFAIK the AttributedModelServices.ComposeExportedValue<T>
extension method for CompositionContainer
registers the given object as a part satisfying contract T
. This means that the object will indeed be used to compose other objects which import T
.
Perhaps more important is what it doesn't do:
- It doesn't try to set any properties with Import attributes. You can do that with
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.
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
.
精彩评论