Rainer Stropek software architects gmbh. Entwicklung modularer Anwendungen mit C# und dem Managed Extensibility Framework (MEF)



Similar documents
Linux & Docker auf Azure

Central Release and Build Management with TFS. Christian Schlag

How To Manage Build And Release With Tfs 2013

Thomas Rümmler AIT GmbH & Co. KG Christian Schlag AIT GmbH & Co. KG. Central Build and Release Management with TFS

BASTA Workshop. Re-Imagine C#

Die SharePoint-Welt für den erfahrenen.net- Entwickler. Fabian Moritz MVP Office SharePoint Server

Rainer Stropek time cockpit. NuGet

Designing and Deploying Messaging Solutions with Microsoft Exchange Server 2010 MOC 10233

TIn 1: Lecture 3: Lernziele. Lecture 3 The Belly of the Architect. Basic internal components of the Pointers and data storage in memory

Microsoft Certified IT Professional (MCITP) MCTS: Windows 7, Configuration ( )

Upgrading Your Skills to MCSA Windows Server 2012 MOC 20417

Kapitel 2 Unternehmensarchitektur III

Diese Liste wird präsentiert von. Netheweb.de

Programmieren von Schnittstellen für LiveCycle ES2-Modulen (November 2009)

Software / FileMaker / Plug-Ins Mailit 6 for FileMaker 10-13

ida.com excellence in dependable automation

Implementing Data Models and Reports with Microsoft SQL Server

CLOUD COMPUTING & WINDOWS AZURE

GETTING FEEDBACK REALLY FAST WITH DESIGN THINKING AND AGILE SOFTWARE ENGINEERING

AnyWeb AG

A: Ein ganz normaler Prozess B: Best Practices in BPMN 1.x. ITAB / IT Architekturbüro Rüdiger Molle März 2009

Embedded Software Development and Test in 2011 using a mini- HIL approach

VSTO 3.0 In Action mit Outlook Lars Keller netcreate OHG

Update to V10. Automic Support: Best Practices Josef Scharl. Please ask your questions here Event code 6262

Is Cloud relevant for SOA? Corsin Decurtins

J2EE-Application Server

O D B C / R O C K E T ( B S / O S D ) V 5. 0 F O R S E S A M / S Q L D A T E : F E B R U A R Y *2 R E L E A S E N O T I C E

Integrating Jalopy code formatting in CVS repositories

Microsoft Nano Server «Tuva» Rinon Belegu

Zielgruppe Dieses Training eignet sich für IT-Professionals.

quick documentation Die Parameter der Installation sind in diesem Artikel zu finden:

Mit einem Auge auf den mathema/schen Horizont: Was der Lehrer braucht für die Zukun= seiner Schüler

MS 10978A Introduction to Azure for Developers

Comparative Market Analysis of Project Management Systems

Stefan Engelberg (IDS Mannheim), Workshop Corpora in Lexical Research, Bucharest, Nov [Folie 1]

CORPORATE DESIGN MANUAL English 5/2015

SPICE auf der Überholspur. Vergleich von ISO (TR) und Automotive SPICE

Getting Started with Telerik Data Access. Contents

Hands-On Lab. Building Applications in Silverlight 4 Module 8: Advanced OOB and MEF. Event Administrator Dashboard

Registries: An alternative for clinical trials?

Sabine Reich SAP. Test Workbench - Introduction

estos uacsta Server for SIP Phones

Finest Laboratory Products

Search Engines Chapter 2 Architecture Felix Naumann

Synopse: EU-GMP- Leitfaden Annex 11 Computerised Systems

Voraussetzungen/ Prerequisites *for English see below*

How To Teach A Software Engineer

Forking, Scratching und Re-Merging

Windows Server und Windows Vista-Gruppenrichtlinien

Programming with the Microsoft.NET Framework Using Microsoft Visual Studio 2005 (VB)

LAB4 Making Classes and Objects

GCE EXAMINERS' REPORTS. GERMAN AS/Advanced

IAC-BOX Network Integration. IAC-BOX Network Integration IACBOX.COM. Version English

Usability in SW-Engineering-Prozessen und in CMMI

FOR TEACHERS ONLY The University of the State of New York

Training for the Implementation of the European Eco-label for Tourist Accommodations and Camp Sites

Dokumentation über die Übernahme von. "GS-R-3" (The Management System for Facilities and Activities) "Sicherheitskriterien für Kernkraftwerke"

Digicomp Microsoft Evolution Day MIM 2016 Oliver Ryf. Partner:

Exemplar for Internal Achievement Standard. German Level 1

Semantic Web. Semantic Web: Resource Description Framework (RDF) cont. Resource Description Framework (RDF) W3C Definition:

Vorläufiges English Programme im akademischen Jahr 2015/2016 Preliminary English Programme in the Academic Year 2015/2016 *for English see below*

How to start up a software business within a cloud computing environment

Vorläufiges English Programme im akademischen Jahr 2015/2016 Preliminary English Programme in the Academic Year 2015/2016 *for English see below*

Vergleich der Versionen von Kapitel 1 des EU-GMP-Leitfaden (Oktober 2012) 01 July November Januar 2013 Kommentar Maas & Peither

Designing and Implementing a Server Infrastructure MOC 20413

LEARNING AGREEMENT FOR STUDIES

How To Analyse A Flugzeugflugfl\U00Fcgels In 3D Cda

Big Data Vendor Benchmark 2015 A Comparison of Hardware Vendors, Software Vendors and Service Providers

It is also possible to combine courses from the English and the German programme, which is of course available for everyone!

Lernsituation 9. Giving information on the phone. 62 Lernsituation 9 Giving information on the phone

Authoring for System Center 2012 Operations Manager

CV - Mario Girsch. Personal data. Presentation

22. April 2010 Siemens Enterprise Communications

Department of Geography - Birgit Sattler - University of Duisburg-Essen ILIAS. in geography and landscape architecture

Gurkensalat statt Spaghetticode. Stuttgarter Testtage 2013

Prepress / Computer To Film / RIP - Xitron Navigator HQ RIP V7.2 für Linotronic von Highwater

Virtual Organization Virtuelle Fabrik

Certificate SAP INTEGRATION CERTIFICATION

Amazon Glacier. Developer Guide API Version

Symantec Backup Exec (TM) 13 Installation Log

FDT for Mobile Devices

Switching Systems Standard ECOSTAR

SAP Enterprise Portal 6.0 KM Platform Delta Features

Cloud Performance Group 1. Event. 14. Januar 2016 / Matthias Gessenay (matthias.gessenay@corporatesoftware.ch)

The Changing Global Egg Industry

SAP GLOBAL DIVERSITY POLICY

STELTSICHVOR. Webdesign-and-IT. TiloBreuer Luftstrase Braunschweig Tel: Mobil: Fax:

Transcription:

Rainer Stropek software architects gmbh Entwicklung modularer Anwendungen mit C# und dem Managed Extensibility Framework (MEF)

Abstract (German) Größere Softwareprojekte werden heute üblicherweise in Teams entwickelt. Dazu kommt, dass sich die Anforderungen, die sie zu erfüllen haben, häufig ändern. Aus diesem Grund sind monolithische Programmriesen nicht mehr zeitgemäß. Die Herausforderung lautet, größere Lösungen in kleinere Einheiten zu zerlegen, an denen unterschiedliche Teammitglieder arbeiten können. Es gilt Komponenten zu entwickeln, die mit klaren Schnittstellen versehen getrennt voneinander versionisiert und verteilt werden. Das Managed Extensibility Framework (MEF) ist ein Werkzeug von Microsoft, mit dem solche Prinzipien leicht umgesetzt werden können. War es früher ein Codeplex-Projekt ist MEF mittlerweile sowohl in.net 4 als auch in Silverlight 4 von Haus aus enthalten. In dem Workshop zeigt Rainer Stropek die Grundlagen von MEF und demonstriert anhand von Beispielen, wie die Bibliothek in der Praxis nutzbringend eingesetzt werden kann.

Introduction software architects gmbh Rainer Stropek Developer, Speaker, Trainer MVP for Windows Azure rainer@timecockpit.com @rstropek http://www.timecockpit.com http://www.software-architects.com

Why does the world need MEF? THE PROBLEM

Original Goals Before MEF Multiple extensibility mechanism for different Microsoft tools (e.g. Visual Studio, Trace Listeners, etc.) Developers outside of MS had the same problem MEF: Provide standard mechanisms for hooks for 3 rd party extensions Goal: Open and Dynamic Applications make it easier and cheaper to build extensible applications and extensions

MEF Hello World [Export(typeof(Shape))] public class Square : Shape // Implementation [Export(typeof(Shape))] public class Circle : Shape // Implementation [Export] public class Toolbox [ImportMany] public Shape[] Shapes get; set; // Additional implementation... [ ] Export with name or type Defaults to typeof(toobox) var catalog = new AssemblyCatalog(typeof(Square).Assembly); var container = new CompositionContainer(catalog); Toolbox toolbox = container.getexportedvalue<toolbox>(); Attributed Programming Model

MEF Hello World (continued) Parts Square, Circle and Toolbox Dependencies Imports (Import-Attribute) E.g. Toolbox.Shapes Capabilities Exports (Export-Attribute) E.g. Square, Circle

MEF Hello World (5 Minutes) DEMO 1

Exports And Imports Export attribute Class Field Property Method Import attribute Field Property Constructor parameter Export and import must have the same contract Contract name and contract type Contract name and type can be inferred from the decorated element

Inherited Exports [Export] public class NumOne [Import] public IMyData MyData get; set; public class NumTwo : NumOne Import automatically inherited Export NOT inherited NumTwo has no exports [InheritedExport] public class NumThree [Export] Public IMyData MyData get; set; Member-level exports are never inherited public class NumFour : NumThree Inherits export with contract NumThree (including all metadata)

MEF Catalogs Catalogs provide components Derived from System.ComponentModel.Composition. Primitives.ComposablePartCatalog AssemblyCatalog Parse all the parts present in a specified assembly DirectoryCatalog Parses the contents of a directory TypeCatalog Accepts type array or a list of managed types AggregateCatalog Collection of ComposablePartCatalog objects

Directory catalog sample HANDS-ON LAB 1 (15 MINUTES)

How to import using MEF IMPORT TYPES

Lazy Imports Imported object is not instantiated immediately Imported (only) when accessed Sample: public class MyClass [Import] public Lazy<IMyAddin> MyAddin get; set;

Prerequisite Imports Composition engine uses parameter-less constructor by default Use a different constructor with ImportingConstructor attribute Sample: [ImportingConstructor] public MyClass( [Import(typeof(IMySubAddin))]IMyAddin MyAddin) _theaddin = MyAddin; Could be removed here; automatically imported

Optional Imports By default composition fails if an import could not be fulfilled Use AllowDefault property to specify optional imports Sample: public class MyClass [Import(AllowDefault = true)] public Plugin theplugin get; set;

Creation Policy RequiredCreationPolicy property CreationPolicy.Any Shared if importer does not explicitly request NonShared CreationPolicy.Shared Single shared instance of the part will be created for all requestors CreationPolicy.NonShared New non-shared instance of the part will be created for every requestor

Part Lifecycle HANDS-ON LAB 2 (5-10 MINUTES)

Advanced exports METADATA AND METADATA VIEWS

Goal Export provides additional metadata so that importing part can decide which one to use Import can inspect metadata without creating exporting part Prerequisite: Lazy import

Metadata and metadata views (10 Minutes) DEMO 2

Metadata namespace MetadataSample public interface ITranslatorMetadata string SourceLanguage get; [DefaultValue("en-US")] string TargetLanguage get; Export Metadata can be mapped to metadata view interface namespace MetadataSample [Export(typeof(ITranslator))] [ExportMetadata("SourceLanguage", "de-de")] [ExportMetadata("TargetLanguage", "en-us")] public class GermanEnglishTranslator : ITranslator public string Translate(string source) throw new NotImplementedException();

Metadata (continued) namespace MetadataSample class Program static void Main(string[] args) var catalog = new AssemblyCatalog( typeof(itranslator).assembly); var container = new CompositionContainer(catalog); // We need a translator from hungarian to english Lazy<ITranslator, ITranslatorMetadata> translator = container.getexports<itranslator, ITranslatorMetadata>().Where(t => t.metadata.sourcelanguage == "hu-hu" && t.metadata.targetlanguage == "en-us").firstordefault();

Custom Export Attributes [TranslatorExport("de-DE", "en-us")] public class GermanEnglishTranslator : Itranslator public string Translate( string source) throw new NotImplementedException(); [Export(typeof(ITranslator))] [ExportMetadata("SourceLanguage", "de-de")] [ExportMetadata("TargetLanguage", "en-us")] public class GermanEnglishTranslator : Itranslator public string Translate( string source) throw new NotImplementedException(); Custom export attributes makes code much cleaner.

Custom Export Attributes (continued) [MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = false)] public class TranslatorExportAttribute : ExportAttribute, ITranslatorMetadata public TranslatorExportAttribute( string sourcelanguage, string targetlanguage) : base(typeof(itranslator)) this.sourcelanguage = sourcelanguage; this.targetlanguage = targetlanguage; public string SourceLanguage get; private set; public string TargetLanguage get; private set;

Using MEF To Extend A WPF Application HANDS-ON LAB 3 (30 MINUTES)

MEF AND SILVERLIGHT

MEF In Silverlight Additional catalog DeploymentCatalog Load exported parts contained in XAP files Provides methods for asynchronously downloading XAP files containing exported parts (DeploymentCatalog.DownloadAsync) Goal Minimize initial load times Application can be extended at run-time

MEF and Silverlight HANDS-ON LAB 4 (15 MINUTES)

Read more about help, find the right tools RESOURCES

Resources About MEF Managed Extensibility Framework on MSDN Managed Extensibility Framework for.net 3.5 on Codeplex Visual Studio 2010 and.net Framework 4 Training Kit