CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

mef injection Scenario

368 Views
Copy Code Show/Hide Line Numbers
   1:  namespace Entity
   2:  {
   3:  public interface IBase
   4:  {
   5:      string Name { get; }    
   6:  }
   7:   
   8:  [Export("Base2", typeof(IBase))]
   9:  [PartCreationPolicy(CreationPolicy.NonShared)]
  10:  public class Base2 : IBase
  11:  {
  12:      public string Name
  13:      {
  14:          get { return "Base2"; }
  15:      }
  16:  }
  17:   
  18:  [Export("Default", typeof(IBase))]
  19:  [PartCreationPolicy(CreationPolicy.NonShared)]
  20:  public class Base : IBase
  21:  {
  22:      public string Name
  23:      {
  24:          get { return "Default"; }
  25:      }
  26:  }
  27:   
  28:  public class EntityBase : IDisposable
  29:  {
  30:      public virtual void Dispose()
  31:      {
  32:          Guid = null;
  33:          ThreadId = 0;
  34:      }
  35:      [Import("Default", typeof(IBase))]
  36:      public virtual IBase Temp { get; set; }
  37:   
  38:      public string Guid { get; set; }
  39:      public int ThreadId { get; set; }
  40:   
  41:  }
  42:   
  43:  [Export(typeof(Course))]
  44:  public class Course : EntityBase
  45:  {
  46:      public string Name { get; set; }
  47:      public int Hour { get; set; }
  48:   
  49:      [Import("Base2", typeof(IBase))]
  50:      public override IBase Temp { get; set; }
  51:   
  52:      public override string ToString()
  53:      {
  54:          return Name + " - " + Hour;
  55:      }
  56:   
  57:      public override void Dispose()
  58:      {
  59:          Name = null;
  60:          Hour = 0;
  61:          base.Dispose();
  62:      }
  63:  }
  64:  }
by codding4fun
  June 08, 2010 @ 1:55am
Tags:
Description:
a scenario which default code of MEF preview 9 does not support it as MEF team said
the resove of mef code is here: http://codepaste.net/kt5oq5

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate