This project is read-only.
1

Closed

Generic support in Silverlight with MefContrib

description

MefContrib Generics do not work with ContractBasedImportDefinition. Changed to use ReflectionMemberImportDefinition.

file attachments

Closed Nov 12, 2012 at 7:58 PM by marcelgood
At this time Cocktail won't directly support the GenericCatalog from MefContrib. MefContrib is no longer being maintained and there are several things that don't work, because open generics are not a first class citizen in MEF for Silverlight. However, the GenericCatalog can still be used with special considerations. Open generics should be imported using constructor or property injection. In general pulling from the container should be minimized in ones application anyway, but in cases where it is necessary, the following trick can be applied to programmatically pull a closed type instance from the container. [Export] public class GenericExport<T> { } [TestMethod] public void ShouldGetGenericInstanceWithImportHelper() { var helper = new GenericImportHelper<GenericExport<object>>(); Composition.BuildUp(helper); Assert.IsNotNull(helper.Instance); } public class GenericImportHelper<T> { [Import] public T Instance { get; set; } }

comments