1 / 36

Visual Studio 2010 and .NET Framework 4 Training Workshop

Visual Studio 2010 and .NET Framework 4 Training Workshop. A Lap Around Managed Extensibility Framework. Name Title Organization Email. Objectives. Understand importance of extensibility to software Understand when and how MEF is used Relation to other existing technologies

Download Presentation

Visual Studio 2010 and .NET Framework 4 Training Workshop

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Studio 2010and.NET Framework 4Training Workshop

  2. A Lap AroundManaged Extensibility Framework Name Title Organization Email

  3. Objectives • Understand importance of extensibilityto software • Understand when and howMEF is used • Relation to other existing technologies • Your feedback

  4. The Problem… Software Maintenance Original Software Development

  5. Managed Extensibility Framework? The Managed Extensibility Framework (MEF) is a new libraryin 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

  6. com·pose [ kəmpṓz ] 2) To put things together to form a whole MSN Encarta

  7. Open/Closed Principle Software entities should be open for extension, but closed for modification.

  8. Known vs. Unknown

  9. MEF Basics… An Application is built of parts.

  10. MEF Basics… Export it. Import it. Compose it.

  11. Part, enter stage left… public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A

  12. Exportit… [Export(typeof(IMortgageCalculator))] public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A

  13. Importit… [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

  14. Compose it. Catalogs provide the parts. Catalog

  15. Compose it. Containeris the matchmaker. Catalog

  16. Compose it. AggregatingCatalog Containeris the matchmaker. DirectoryCatalog AssemblyCatalog Catalog TypeCatalog

  17. Step 1 – MEF Basics

  18. Don’t forget the metadata… [Export(typeof(IMortgageCalculator))] [ExportMetadata(“Calculation”, “Simple”)] [ExportMetadata(“Tax Aware”, null)] public class SimpleMortgageCalculator : IMortgageCalculator { public ILogger Logger { get; set; } public float Calculate() { Logger.Log("Calculating Mortgage"); return ...; } } Part A

  19. Parts can be lazy… [Import(typeof(ILogger))] public ILogger Logger { get; set; } Part A Part B

  20. Parts can be lazy… [Import(typeof(ILogger))] public ILoggerLazy<ILogger>Logger { get; set; } Part A Lazy <B>

  21. Step 2 – Metadata and Lazy Evaluation

  22. The slippery slope… [Export(typeof(IMortgageCalculator))] [ExportMetadata(“Calculation”, “Simple”)] [ExportMetadata(“Tax Aware”, null)] [ExportMetadata(“This”, “foo”)] [ExportMetadata(“That”, “bar”)] Part A

  23. The slippery slope… solved [Export(typeof(IMortgageCalculator))] [ExportMetadata(“Calculation”, “Simple”)] [ExportMetadata(“Tax Aware”, null)] [ExportMetadata(“This”, “foo”)] [ExportMetadata(“That”, “bar”)] [Export(typeof(IMortgageCalculator))] [CalcCapabilities( Mode=Complexity.Simple, TaxAware=true, This=“foo”, That=“bar”)] Part A

  24. Step 3 – Strongly-Typed Metadata

  25. The importance of context!

  26. Step 4 – Context Awareness

  27. Lifetime Shared Non-Shared Container Container Part A Part B Part B Part B

  28. Step 5 – Lifetime

  29. But…… Where are the so-called external dependencies?

  30. .\Extensions CompositionContainer

  31. Step 6 – External Dependencies

  32. The Power of Being Declarative Whatvs. How

  33. The Problem… Software Maintenance Original Software Development

  34. The Solution… Software Maintenance Original Software Development

  35. Resources • http://mef.codeplex.com • Clean Code, Robert C. Martin • Working Effectively with Legacy Code, Michael Feathers • Refactoring, Martin Fowler

More Related