With MEF 1 it was possible to compose an existing object to the container with the ComposeExportedValue(...)-Method (container.ComposeExportedValue...
). How can this be done with Microsoft.Composition (MEF 2)? I can't find any Method for this purpose.
相关问题
- Wrapping Angular components which has Parent/Child
- How to I access the DbContext of EF core from anot
- How can I get all singleton instances from a Guice
- Unity and delegate
- How Use shared preference with injectable and get_
相关文章
- Injecting an IEnumerable into a constructor with a
- ASP.NET Core DbContext injection
- DI container, factory, or new for ephemeral object
- How does @Inject in Scala work
- When to use interfaces, and when to use higher ord
- @EntityListeners Injection + jUnit Testing
- conditional beans using spring
- Dependency Injection Container
https://mef.codeplex.com/ states that
And as far as I know from my experience System.Composition doesn't support dynamic composition. If you need such capabilities you've got to use standard MEF (System.ComponentModel.Composition.*).
I will have a shot at this one. Granted, I am only about a week in on learning MEF 2 myself, after having some limited exposure to MEF 1. So, please take that in consideration with the following answer as it could be completely wrong. Also, I have found documentation very poor and out of date so it has been an uphill battle in every respect thus far.
In my solution, I made use of the
ExportDescriptorProvider
and extended it as anInstanceExportDescriptorProvider
as the following code demonstrates.(Please note this should be considered proof-of-concept and not final code!)
Supporting test (using xUnit 2.0 paired with AutoFixture) to show how this would be used is as follows:
In my case I want to have access to the assemblies passed into the
ContainerConfiguration
(not seen/tested in the above example) so that is why I am testing with Assemblies.Hopefully this will be enough to get you on on your way. Or some way, in any case.