<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:georss="http://www.georss.org/georss" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Central Florida Software Blog - Extensibility</title>
    <link>http://www.centralflsoftware.com/blog/</link>
    <description>Innovation. Imagination. Delivered.</description>
    <language>en-us</language>
    <copyright>Christopher L Price</copyright>
    <lastBuildDate>Wed, 22 Jul 2009 12:47:20 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>blog@centralflsoftware.com</managingEditor>
    <webMaster>blog@centralflsoftware.com</webMaster>
    <item>
      <trackback:ping>http://www.centralflsoftware.com/blog/Trackback.aspx?guid=67ef544c-678d-46c8-a7ba-7f3e56544d0c</trackback:ping>
      <pingback:server>http://www.centralflsoftware.com/blog/pingback.aspx</pingback:server>
      <pingback:target>http://www.centralflsoftware.com/blog/PermaLink,guid,67ef544c-678d-46c8-a7ba-7f3e56544d0c.aspx</pingback:target>
      <dc:creator>Christopher Price</dc:creator>
      <georss:point>28.171599 -82.001953</georss:point>
      <wfw:comment>http://www.centralflsoftware.com/blog/CommentView,guid,67ef544c-678d-46c8-a7ba-7f3e56544d0c.aspx</wfw:comment>
      <wfw:commentRss>http://www.centralflsoftware.com/blog/SyndicationService.asmx/GetEntryCommentsRss?guid=67ef544c-678d-46c8-a7ba-7f3e56544d0c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <strong>Managed Extensibility Framework
(MEF)</strong>
        <p>
          <em>Below are my review notes from the 10-4 video on the upcoming Managed Extensibility
Framework in version 4.0</em>
        </p>
        <p>
        </p>
        <ol>
          <li>
A new library available in v4.0</li>
          <li>
Software entities should be open to extension, but closed to modification (Open/Closed
Principle)</li>
          <li>
Basics: 
<ul><li>
An application is built of parts or individual pieces composed together</li><li>
Three Steps: 
<ol><li>
Export a part (Attribute: [Export(typeof(IMortgageCalculator))])</li><li>
Import a part (Attribute: [Import(typeof(Logger))])</li><li>
Compose a part 
<ul><li>
Catalogs provide the parts (TypeCatalog, AssemblyCatalog, DirectoryCatalog, AggregatingCatalog)</li><li>
Container is the matchmaker</li></ul></li></ol></li></ul></li>
          <li>
Why? - Build a network aware app without changing the core window code (i.e. extend
behavior without modifying code)</li>
        </ol>
        <u>Sample</u>
        <code>
          <pre>
namespace Sample
{
	public interface IMortgageRateRepository
	{
		public IList<Rates>
GetCurrentRates(); } } 
</Rates></pre>
        </code>
        <p>
          <em>Notice that in the concrete implementation of the interface we use the Export
Attribute</em>
        </p>
        <code>
          <pre>
namespace Sample
{
	[Export(typeof(IMortgageRateRepository))]
	public class ELoanMortgageRateRepository: IMortgageRateRepository
	{
		public IList<Rates>
GetCurrentRates() { return new List<Rates>
(); } } } 
</Rates></Rates></pre>
        </code>
        <p>
          <em>Alot of stuff happening here, we use the export attribute at the class level and
then the Import attribute on our dependency. I also want to point out that we no longer
'new' up an object. Instead we implement the IPartImportsSatisfiedNotification interface
and move out binding logic to that event handler (basically we can't use the objects
until they have been imported by the container). </em>
        </p>
        <code>
          <pre>
namespace Sample
{
	[Export]
	public partial class MortgageRates: Window, IPartImportsSatisfiedNotification
	{
		[Import]
		IMortgageRateRepository MortgageRateRepository  { get; set; }

		public MortgageRates()
		{
			InitializeComponent();

			//MortgageRateRepository = new MortgageRateRepository();
			//grid.ItemSource = MortgageRateRepository.GetCurrentRates();
		}

		public void OnImportsSatisified()
		{
			Dispatcher.Invoke(new Action(() =&gt;
			{
				MortgageRateRepository = new MortgageRateRepository();
				grid.ItemSource = MortgageRateRepository.GetCurrentRates();	
			}));
		}
	}
}
</pre>
        </code>
        <p>
          <em>Finally, where the magic happens. We create an AssemblyCatalog and then a CompositionContainer.
Notice that instead of 'Newing' up an instance of the window directly. We get an instance
of the exported object from the container.</em>
        </p>
        <code>
          <pre>
namespace Sample
{
	public partial class App: Application
	{
		var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
		var container = new CompositionContainer(catalog);

		var window = container.GetExportedObject&lt;MortgageRates&gt;();
		//var window = new MortgageRates();

		window.Show();
	}
}
</pre>
        </code>
        <img width="0" height="0" src="http://www.centralflsoftware.com/blog/aggbug.ashx?id=67ef544c-678d-46c8-a7ba-7f3e56544d0c" />
      </body>
      <title>Managed Extensibility Framework</title>
      <guid isPermaLink="false">http://www.centralflsoftware.com/blog/PermaLink,guid,67ef544c-678d-46c8-a7ba-7f3e56544d0c.aspx</guid>
      <link>http://www.centralflsoftware.com/blog/2009/07/22/ManagedExtensibilityFramework.aspx</link>
      <pubDate>Wed, 22 Jul 2009 12:47:20 GMT</pubDate>
      <description>&lt;strong&gt;Managed Extensibility Framework (MEF)&lt;/strong&gt; 
&lt;p&gt;
&lt;em&gt;Below are my review notes from the 10-4 video on the upcoming Managed Extensibility
Framework in version 4.0&lt;/em&gt; 
&lt;/p&gt;
&lt;p&gt;
&lt;ol&gt;
&lt;li&gt;
A new library available in v4.0&lt;/li&gt;
&lt;li&gt;
Software entities should be open to extension, but closed to modification (Open/Closed
Principle)&lt;/li&gt;
&lt;li&gt;
Basics: 
&lt;ul&gt;
&lt;li&gt;
An application is built of parts or individual pieces composed together&lt;/li&gt;
&lt;li&gt;
Three Steps: 
&lt;ol&gt;
&lt;li&gt;
Export a part (Attribute: [Export(typeof(IMortgageCalculator))])&lt;/li&gt;
&lt;li&gt;
Import a part (Attribute: [Import(typeof(Logger))])&lt;/li&gt;
&lt;li&gt;
Compose a part 
&lt;ul&gt;
&lt;li&gt;
Catalogs provide the parts (TypeCatalog, AssemblyCatalog, DirectoryCatalog, AggregatingCatalog)&lt;/li&gt;
&lt;li&gt;
Container is the matchmaker&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
Why? - Build a network aware app without changing the core window code (i.e. extend
behavior without modifying code)&lt;/li&gt;
&lt;/ol&gt;
&gt;
&lt;u&gt;Sample&lt;/u&gt; &lt;code&gt; &lt;pre&gt;
namespace Sample
{
	public interface IMortgageRateRepository
	{
		public IList&lt;Rates&gt;
GetCurrentRates(); } } 
&lt;/pre&gt;
&lt;/code&gt; 
&lt;p&gt;
&lt;em&gt;Notice that in the concrete implementation of the interface we use the Export
Attribute&lt;/em&gt; 
&lt;/p&gt;
&lt;code&gt; &lt;pre&gt;
namespace Sample
{
	[Export(typeof(IMortgageRateRepository))]
	public class ELoanMortgageRateRepository: IMortgageRateRepository
	{
		public IList&lt;Rates&gt;
GetCurrentRates() { return new List&lt;Rates&gt;
(); } } } 
&lt;/pre&gt;
&lt;/code&gt; 
&lt;p&gt;
&lt;em&gt;Alot of stuff happening here, we use the export attribute at the class level and
then the Import attribute on our dependency. I also want to point out that we no longer
'new' up an object. Instead we implement the IPartImportsSatisfiedNotification interface
and move out binding logic to that event handler (basically we can't use the objects
until they have been imported by the container). &lt;/em&gt; 
&lt;/p&gt;
&lt;code&gt; &lt;pre&gt;
namespace Sample
{
	[Export]
	public partial class MortgageRates: Window, IPartImportsSatisfiedNotification
	{
		[Import]
		IMortgageRateRepository MortgageRateRepository  { get; set; }

		public MortgageRates()
		{
			InitializeComponent();

			//MortgageRateRepository = new MortgageRateRepository();
			//grid.ItemSource = MortgageRateRepository.GetCurrentRates();
		}

		public void OnImportsSatisified()
		{
			Dispatcher.Invoke(new Action(() =&gt;
			{
				MortgageRateRepository = new MortgageRateRepository();
				grid.ItemSource = MortgageRateRepository.GetCurrentRates();	
			}));
		}
	}
}
&lt;/pre&gt;
&lt;/code&gt; 
&lt;p&gt;
&lt;em&gt;Finally, where the magic happens. We create an AssemblyCatalog and then a CompositionContainer.
Notice that instead of 'Newing' up an instance of the window directly. We get an instance
of the exported object from the container.&lt;/em&gt; 
&lt;/p&gt;
&lt;code&gt; &lt;pre&gt;
namespace Sample
{
	public partial class App: Application
	{
		var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly());
		var container = new CompositionContainer(catalog);

		var window = container.GetExportedObject&amp;lt;MortgageRates&amp;gt;();
		//var window = new MortgageRates();

		window.Show();
	}
}
&lt;/pre&gt;
&lt;/code&gt;&lt;img width="0" height="0" src="http://www.centralflsoftware.com/blog/aggbug.ashx?id=67ef544c-678d-46c8-a7ba-7f3e56544d0c" /&gt;</description>
      <comments>http://www.centralflsoftware.com/blog/CommentView,guid,67ef544c-678d-46c8-a7ba-7f3e56544d0c.aspx</comments>
      <category>.Net v4.0</category>
      <category>Extensibility</category>
    </item>
  </channel>
</rss>