InheritedExport

Leggendo qualche post qua e là e spulciando i sorgenti di MEF ho notato che oltre al classico ExportAttribute è presente anche InheritedExportAttribute!

Qual è la differenza tra i due?
Semplice! Con quest’ultimo possiamo decorare direttamente il nostro contratto

   1: [InheritedExport]
   2: public interface IPlugin
   3: {
   4:     string Name { get; set; }
   5:     string Description { get; set; }
   6:     string AuthorName { get; set; }
   7: }

senza dover decorare ogni plugin con ExportAttribute :)

   1: public class FirstPlugin : IPlugin
   2:     {
   3:         public FirstPlugin()
   4:         {
   5:             this.Name = "FirstPlugin";
   6:             this.Description = "FirstPlugin";
   7:             this.AuthorName = "Federico Degrandis";
   8:         }
   9:  
  10:         #region IPlugin Members
  11:  
  12:         public string Name { get; set; }
  13:  
  14:         public string Description { get; set; }
  15:  
  16:         public string AuthorName { get; set; }
  17:  
  18:         #endregion
  19:     }

Logicamente tutte le classi che implementano l’interfaccia IPlugin, all’interno degli assembly caricati dai catalog, saranno visti come composable part!

Buon MEF a tutti quanti :D

posted @ mercoledì 3 marzo 2010 01:28

Print
Comments have been closed on this topic.