KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
OK I'm pretty sure this is something blindingly obvious but I'm not finding it. I'm trying to export a object from MEF container based on it's Metadata. I've seen this done in tutorials like this one: http://blog.maartenballiauw.be/post/2009/04/21/ASPNET-MVC-and-the-Managed-Extensibility-Framework-%28MEF%29.aspx However my export doesn't have the Metadata property that is necessary for this to work. What could be the problem there? [Export(typeof(IController))] [ExportMetadata("controllerName","Home")] [PartCreationPolicy(CreationPolicy.NonShared)] public class HomeController : Controller{} and again public class MyControllerFactory : IControllerFactory { private readonly CompositionContainer _container; public MyControllerFactory(CompositionContainer container) { _container = container; } public IController CreateController(System.Web.Routing.RequestContext requestContext, string controllerName) { var controllerExport = _container.GetExports<IController>(). Where(exp => exp.Metadata) //Here it doesn't have the Metadata property. } } I understand that the GetExports returns a collection of Lazy that do of course not have the Metadata property but it's assumed in most tutorials I look through. How do I do this correctly? EDIT This is what I did: public interface IControllerMetaData { string Name { get; } string Subdomain { get; } } [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] public class ControllerMetadataAttribute : ExportAttribute { public ControllerMetadataAttribute(string name, string subdomain) : base(typeof(IControllerMetaData))
Tags (comma-separated)
Save Edits
Cancel