Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>When using MEF, you cannot export properties or methods (as types) of some class, you need to export the class itself, so your code should be like this:</p> <pre><code> [Export(typeof(Handler))] public class HandlerUser : Handler { public string Name { get; set; } public HandlerUser() : base() { } } </code></pre> <p>But since you are using MEF, this means that you are trying to add extensibility to you application, considering this, i would make "Handle" an Interface and not a class, so this way anyone can implement the way they want, they just need to implement the interface.</p> <p>In this case, would be like:</p> <pre><code> public interface IHandler { string Message { get; } public void Create(string msg); } [Export(typeof(Handler))] public class HandlerUser : IHandler { public string Name { get; set; } public string Message { get; private set;} public HandlerUser() { } public void Create(string msg) { this.Message = msg } } </code></pre> <p><strong>Edit:</strong></p> <p>I have updated the answer to be clear about how MEF works with exports, you can in fact export a property, but not in the context of the question. When you do this, you will be exporting by the property name "Handler" and not the typeof(Handler) like you do in Class definition. Property and method exports are a cool feature, but there are some limitations (the max number of parameters of a method export is 4!), prefer Class Exports where possible.</p> <p>More information on exporting using MEF can be found <a href="https://mef.codeplex.com/wikipage?title=Declaring%20Exports" rel="nofollow">here</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload