Presentation is loading. Please wait.

Presentation is loading. Please wait.

Glenn Block Blogs/msdn.com/gblock @gblock MEF in the real world Glenn Block Blogs/msdn.com/gblock @gblock.

Similar presentations


Presentation on theme: "Glenn Block Blogs/msdn.com/gblock @gblock MEF in the real world Glenn Block Blogs/msdn.com/gblock @gblock."— Presentation transcript:

1 Glenn Block Blogs/msdn.com/gblock @gblock
MEF in the real world Glenn Block Blogs/msdn.com/gblock @gblock

2 Who am I? Program Manager on the MEF team for V1
Drove the design of many key features Worked with many customers building systems on MEF Truly believe that MEF can dramatically improve your development

3 How can we get from this?

4 To this

5 And from here

6 To here

7 MEF quick glance Main Window 3. Compose 1. Import 2. Export

8 Export it. Import it. Compose it. MEF Basics…
There are really three concepts you need to understand with MEF Export It – Components (we call them Parts) provide capabilities to other parts called Exports. To Export you decorate your class with an Export attribute essentially saying, “Here I am providing this” Import It – To use the capabilities of another part, you Import it. To import your decorate a property on your part with an Import attribute which means “I need this” Compose It – The last step is putting the pieces together. The container (CompositionContainer) is responsible for that job. We’ll see how that works soon.

9

10 Choose your flavor! MEF .NET 4.0 MEF Silverlight 4 MEF .NET 3.5
MEF on Mono MEF on Moonlight PocketMEF

11 What we learned / recommend
MEF is NOT a UI framework You don’t have to build entirely on MEF / you can use it for existing systems Don’t expose the container directly, use services Create custom attributes Use Inherited Export for invisibility Use property exports for legacy

12 What people like Simple to use Powerful/Flexible Solves the problem
Extensible MEF on Codeplex / MSPL

13 What some people don’t like*
Hard to debug Hard to know what to extend / how to extend Hard to use in ASP.NET .NET Platform not compositionally friendly Versioning issues Attribute noise Lack of AOP support No support for open generics

14 Products/projects using MEF
Visual Studio 2010 RavenDB Caliburn Jounce ILSpy Glimpse Prism

15 Provisioner OCS2007 R2 and Lync 2010 Implementations
[MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class ExportWithContextAttribute : ExportAttribute { public object Context { get; set; } public ExportWithContextAttribute(Type contractType, object context) : base(contractType) { this.Context = context; } } public interface IProvisioner { // Methods List<ApplicationPool> GetApplicationPool(string applicationName); bool CreateApplicationPool(ApplicationPool applicationPool); void UpdateApplicationPool(ApplicationPool applicationPool); bool DeleteApplicationPool(string applicationName); bool DeleteApplicationPool(ApplicationPool applicationPool); bool ApplicationPoolExists(string applicationName); List<Contact> GetContacts(string applicationName); Contact GetContact(string applicationName, string uri); bool AddContact(ApplicationPool applicationPool, Contact contact); bool UpdateContact(ApplicationPool applicationPool, Contact contact); bool DeleteContact(ApplicationPool applicationPool, Contact contact); string GetApplicationPoolGRUU(ApplicationPool applicationPool); } OCS2007 R2 and Lync 2010 Implementations [ExportWithContext(typeof(IProvisioner), CommunicationsServerVersion.LyncServer2010)] public class LyncPool : IProvisioner, IPartImportsSatisfiedNotification { } [ExportWithContext(typeof(IProvisioner), CommunicationsServerVersion.OCS2007R2)] public class OCSFrontEnd: IProvisioner, IPartImportsSatisfiedNotification { }

16 Contact Center for Microsoft Lync 2010
Modular, integrated software suite that provides sophisticated contact center functionality on the Microsoft© Lync™ Server 2010 platform. Receives Customer Interaction Solutions Magazine’s 2010 Product of the Year Award

17 Where we use MEF prairieFyre uses MEF in:
Our Ignite client application Our Lync Provisioner service As time goes on our use of MEF continues to grow. MEF has significant roles in our v.Next planning. MEF allows us to decouple components in our applications/services and enables a great extensibility story.

18 Ignite The call center agent client application MVVM with WPF

19 What MEF does for Ignite
Ignite’s MVVM framework was written with MEF at the base. MEF resolves Views and ViewModels MEF resolves dependencies that Views and ViewModels require for core functionality. Communications to our real time streams. Event Aggregator By building the base on MEF for Views, ViewModels and Event Aggregator we now have a rich plugin extensibility model available for v.Next.

20 BaseViewModel public class BaseViewModel<TViewModel> : IViewModel, INotifyPropertyChanged, IPartImportsSatisfiedNotification { // Composed Dependencies from MEF [Import] public IEventAggregator Events { get; set; } public BaseViewModel() { if (DesignHelpers.DesignMode == false) ApplicationHost.Container.SatisfyImportsOnce(this); } public virtual void OnImportsSatisfied() { Events.Subscribe(this); } public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { OnPropertyChanged(this, propertyName); } protected void OnPropertyChanged(object sender, string propertyName) { OnPropertyChanged(sender, new PropertyChangedEventArgs(propertyName)); } protected void OnPropertyChanged(object sender, PropertyChangedEventArgs e) { if (PropertyChanged != null) PropertyChanged(sender, e); } }

21 Provisioner Service Configures OCS 2007 or Lync based on what the customer has installed. OCS 2007 Enterprise Config Provisioner Service Lync 2010

22 What MEF does for the Provisioner
The Provisioner needs to support configuring OCS 2007 and Lync 2010 and future Lync releases. We decoupled the service in 3 parts. Model Audit Controller IProvisioner By detecting if the service is running against OCS 2007 or Lync we use MEF to resolve which implementation of IProvisioner to audit against. MEF helps us going forward for swapping out IProvisioner implementations as Lync evolves.

23 Provisioner OCS2007 R2 and Lync 2010 Implementations
[MetadataAttribute] [AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] public class ExportWithContextAttribute : ExportAttribute { public object Context { get; set; } public ExportWithContextAttribute(Type contractType, object context) : base(contractType) { this.Context = context; } } public interface IProvisioner { // Methods List<ApplicationPool> GetApplicationPool(string applicationName); bool CreateApplicationPool(ApplicationPool applicationPool); void UpdateApplicationPool(ApplicationPool applicationPool); bool DeleteApplicationPool(string applicationName); bool DeleteApplicationPool(ApplicationPool applicationPool); bool ApplicationPoolExists(string applicationName); List<Contact> GetContacts(string applicationName); Contact GetContact(string applicationName, string uri); bool AddContact(ApplicationPool applicationPool, Contact contact); bool UpdateContact(ApplicationPool applicationPool, Contact contact); bool DeleteContact(ApplicationPool applicationPool, Contact contact); string GetApplicationPoolGRUU(ApplicationPool applicationPool); } OCS2007 R2 and Lync 2010 Implementations [ExportWithContext(typeof(IProvisioner), CommunicationsServerVersion.LyncServer2010)] public class LyncPool : IProvisioner, IPartImportsSatisfiedNotification { } [ExportWithContext(typeof(IProvisioner), CommunicationsServerVersion.OCS2007R2)] public class OCSFrontEnd: IProvisioner, IPartImportsSatisfiedNotification { }

24 Our Future MEF Use We plan to increase our use of MEF in both Ignite and the Lync Provisioner service. Planning has begun to use MEF as the base for new products we are working on now to release to market soon.

25 What’s next for MEF?

26 Stay up to date with MSDN Belux
Register for our newsletters and stay up to date: Technical updates Event announcements and registration Top downloads Follow our blog Join us on Facebook LinkedIn: Download MSDN/TechNet Desktop Gadget Please keep this slide

27 TechDays On-Demand Watch this session on-demand via Channel9 Download to your favorite MP3 or video player Get access to slides and recommended resources by the speakers

28 THANK YOU


Download ppt "Glenn Block Blogs/msdn.com/gblock @gblock MEF in the real world Glenn Block Blogs/msdn.com/gblock @gblock."

Similar presentations


Ads by Google