Download presentation
Presentation is loading. Please wait.
1
Tech·Ed North America 2009 11/10/2018 2:43 PM
© 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
2
Managed Extensibility Framework
Tech·Ed North America 2009 11/10/2018 2:43 PM Managed Extensibility Framework Jason “For The Developers” Olson © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
3
From The 1967 World’s Fair (most successful fair ever, attracting over 50 million visitors)
Expo 67 was nicknamed "Man and his World", taken from Antoine de Saint Exupéry's memoir Terre des hommes, (literally "Land of Men"), translated as Wind, Sand and Stars. Housing was one of the main themes of Expo 67. Habitat 67 then became a thematic pavilion visited by thousands of visitors who came from around the world. During Expo 67 it was also the temporary residence of the many dignitaries coming to Montreal. It was designed to integrate the variety and diversity of scattered private homes with the economics and density of a modern apartment building. Modular, interlocking concrete forms define the space. The project was designed to create affordable housing with close but private quarters, each equipped with a garden. The building was believed to illustrate the new lifestyle people would live in increasingly crowded cities around the world.[1] The complex was originally meant to be vastly larger. Ironically, the building's units are now quite expensive from demand rather than "affordable" due to its architectural cachet. It is owned by its tenants who formed a limited partnership that purchased the building from the Canada Mortgage and Housing Corporation in 1985.
4
Objectives Understand importance of Extensibility to software
Understand when MEF would be used Understand how MEF is used
5
The Problem… Software Maintenance Original Software Development
Nearly 80% of software development costs is in the maintenance of software. Original Software Development
6
Managed Extensibility Framework?
The Managed Extensibility Framework (MEF) is a new library in the .NET Framework that enables greater reuse of applications and components. Using MEF, .NET applications can make the shift from being statically compiled to dynamically composed MESSAGING: New Library = just an assembly, a normal .dll, used by any .NET language Dynamically Composed = composition takes place at runtime and composition behavior differs depending on how it is configured.
7
com·pose [ kəm pṓz ] 2) To put things together to form a whole
MSN Encarta
8
Open/Closed Principle
Software entities should be open for extension, but closed for modification.
9
Known vs. Unknown MESSAGING:
Due to it’s declarative-based and discovery-enabled approach, MEF becomes very powerful to use in an application where it is being used to put together a bunch of potentially unknown parts into a working application. You might also think about this as a 3rd party extending your application. When you are compiling your application (long before you ship), you have absolutely no idea on what sorts of extensions might be built for your application into the future. That’s the power of extensible applications, they can be extended and used in ways the original authors perhaps didn’t expect, or didn’t have the time to do themselves. If you are concerned strictly with the “known” part of the equation (composing different software entities together that are all known at compile time), there are other solutions that are available today that are very powerful for this scenario: namely IoC containers (IoC = Inversion of Control). The Managed Extensibility Framework was designed primarily with the unknown aspect of extension in mind.
10
Let me know you’re there!
send hello How well I’m doing? send is cool or is not cool Sample messages: #dtl328 hello / #dtl328 is cool / #dtl328 is not cool
11
Twitter – Demo Dashboard
11/10/2018 2:43 PM demo If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Twitter – Demo Dashboard © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
12
An Application is built of parts.
MEF Basics… An Application is built of parts.
13
MEF Basics… Export it. Import it. Compose it.
14
Part A Part, enter stage left…
public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() Logger.Log("Calculating Mortgage"); return ...; } Part A MESSAGING: So, if a MEF-aware application is built of parts, parts can be thought of as the “heart” of a MEF-aware application. Let’s take a look at a simple Part. In this case, it is a class called SimpleMortgageCalculator that has one dependency it needs satisfied, an ILogger. Let’s see how we would use MEF to declare the needs this part has in order to be composed.
15
Part A Export it. Export [Export(typeof(IMortgageCalculator))]
public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() Logger.Log("Calculating Mortgage"); return ...; } Part A MESSAGING: Now in the case of Exports, exports are contracts a part offers to other parts. In the case of our SimpleMortageCalculator, we are exporting ourself as an IMortgageCalculator. This is done very easily by decorating our class with an Export class and specifying that we would like to export ourselves specifically as an IMortgageCalculator (it’s important to note, that if you left out “typeof(IMortgageCalculator)”, the class would be exported as a SimpleMortgageCalculator instead (so other parts importing IMortgageCalculator would not find us)). Once again, very simple. Decorate with an Export attribute and MEF has all the information it needs for this specific part. Export
16
Part A Import it. Import [Export(typeof(IMortgageCalculator))]
public class SimpleMortgageCalculator : IMortgageCalculator { [Import(typeof(ILogger))] public ILogger Logger { get; set; } public float Calculate() Logger.Log("Calculating Mortgage"); return ...; } Part A MESSAGING: In the case of our SimpleMortageCalculator, we simply decorate our ILogger property with an Import attribute that specifies what type we need to import (this is because we could very well be importing a different type of contract than is satisfied directly (see the slide on Lazy for more info)). This is how simple it is. Decorate with an Import attribute and MEF has all the information it needs for this specific part. NOTES: This could also be done on a constructor that accepts an ILogger and uses the ImportingConstructor attribute. Import
17
Catalogs provide the parts.
Compose it. Catalogs provide the parts. Catalog
18
Container is the matchmaker.
Compose it. Container is the matchmaker. Catalog
19
Container is the matchmaker.
Compose it. AggregatingCatalog Container is the matchmaker. DirectoryCatalog Catalog AssemblyCatalog MESSAGING: Now that we’ve declared all our Imports and Exports, how are they all matched up together? This is the job of the container. The container is the “match maker” if you will. An application will ask the configured container for an object of a given type, then the container will take care of building up the entire object graph and returning the necessary object. All of this matching is handled by the container itself, the user doesn’t have to think about it at all. TypeCatalog
20
demo Step 1 - MEF Basics 11/10/2018 2:43 PM
If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Step 1 - MEF Basics © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
21
The Power of Being Declarative
What vs. How Benefits of attribute-based model Taking a step further, what XAML integration opens up
22
Parts can be lazy… Part A Part B [Import(typeof(ILogger))]
public ILogger Logger { get; set; } Part A Part B MESSAGING: Sometimes though, you may not want to import the part itself (let’s say you may only need to use it in specific situations and hence don’t want to create it in every situation, or you might want to programatically determine whether it should be imported or not). This can be done in MEF through lazy imports. To lazily import a part, rather than having the property imported to be the type of the import directly, you can import Export<T> (where T is the type you are importing). Once you have a reference to the Export, you have direct access to information like the contract for that Export as well as any Metadata for that Export (which can then be used to query against to determine whether the import should be used or not).
23
Parts can be lazy… Part A Export <B> [Import(typeof(ILogger))]
public ILogger Export<ILogger> Logger { get; set; } Part A Export <B> MESSAGING: Sometimes though, you may not want to import the part itself (let’s say you may only need to use it in specific situations and hence don’t want to create it in every situation, or you might want to programatically determine whether it should be imported or not). This can be done in MEF through lazy imports. To lazily import a part, rather than having the property imported to be the type of the import directly, you can import Export<T> (where T is the type you are importing). Once you have a reference to the Export, you have direct access to information like the contract for that Export as well as any Metadata for that Export (which can then be used to query against to determine whether the import should be used or not).
24
demo Step 2 - Lazy Evaluation 11/10/2018 2:43 PM
If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Step 2 - Lazy Evaluation © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
25
The importance of context!
26
Step 3 – Context-Awareness
11/10/2018 2:43 PM demo If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Step 3 – Context-Awareness © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
27
Lifetime Container Container Shared Non-Shared Part A Part B Part B
MESSAGING: MEF also provides parts the capability of specifying what their lifetime behavior should be (like whether one instance of a part should be used everywhere, or whether a new instance should be created for each new request for that part). Among other things, this is enables scenarios like using MEF in a web server scenario or in a scenario where you might require a part to be isolated from other instances of the same part. This can be specified very easily using the PartCreationOptions on either the Import or Export attribute.
28
demo Step 4 - Lifetime 11/10/2018 2:43 PM
If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Step 4 - Lifetime © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
29
so-called external dependencies?
But Jason… Where are the so-called external dependencies?
30
.\Extensions CompositionContainer
31
Step 5 – External Dependencies
11/10/2018 2:43 PM demo If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Step 5 – External Dependencies © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
32
How does this compare to…
System.AddIn? IoC Containers? Hand-Rolled Plugin Systems?
33
Twitter – Demo Dashboard Dissection
11/10/2018 2:43 PM demo If you would like to host your demo on the Virtual Server, please use the myVPC demo slide, not this slide. Twitter – Demo Dashboard Dissection © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
34
The Problem… Software Maintenance Original Software Development
Nearly 80% of software development costs is in the maintenance of software. Original Software Development
35
Solving The Problem… Original Software Development Software
Maintenance Original Software Development Nearly 80% of software development costs is in the maintenance of software.
36
Resources http://mef.codeplex.com Clean Code, Robert C. Martin
Required Slide Speakers, TechEd 2009 is not producing a DVD. Please announce that attendees can access session recordings at TechEd Online. Resources Sessions On-Demand & Community Clean Code, Robert C. Martin
37
Related Content Breakout Sessions
Required Slide Speakers, please list the Breakout Sessions, TLC Interactive Theaters and Labs that are related to your session. Related Content Breakout Sessions DTL314 – Understanding Code Extensibility WUX314 – SOLIDify Your ASP.NET MVC Apps DPR204 – Lean Practices, Agile Techniques BOF54 – Agile Development w/ Microsoft .NET
38
Complete an evaluation on CommNet and enter to win!
Required Slide Complete an evaluation on CommNet and enter to win!
39
Required Slide 11/10/2018 2:43 PM © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION. © 2007 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.