Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
OPN07<br />Fun with ASP.NET MVC 3, MEF and NuGet<br />Maarten Balliauw<br />Technical Consultant<br />RealDolmen<br />@maa...
Notes (hidden)<br />So you have a team of developers… And a nice architecture to build on… How about making that architect...
Who am I?<br />Maarten Balliauw<br />Antwerp, Belgium<br />www.realdolmen.com<br />Focus on web<br />ASP.NET, ASP.NET MVC,...
Agenda<br />Technologies & techniques used<br />ASP.NET MVC 3<br />Managed Extensibility Framework (MEF)<br />NuGet<br />C...
ASP.NET MVC 3<br />All the new stuff:<br />Razor view engine<br />Global Action Filters<br />Unobtrusive Ajax & Client Val...
var partA =new PartA(new PartB())<br />Sidenote: Dependency Injection?<br />I need a “Part B” !<br />Coming up!<br />Part ...
Container<br />Sidenote: Dependency Injection?<br />I need a “Part B” !<br />Let me see...<br />There you go!<br />Part A<...
How does this fit into ASP.NET MVC 3?<br />ASP.NET MVC 3 uses DependencyResolver<br />: IDependencyResolver<br />GetServic...
How does this fit in ASP.NET MVC 3?<br />ASP.NET MVC will / can query the IDependencyResolver for<br />Controllers<br />Vi...
Dependency Injection in ASP.NET MVC 3<br />demo <br />
Managed Extensibility Framework (MEF)<br />Cool as ICE: Import, Compose, Export<br />[Import]Ilogger logger;<br />MEF cata...
Options for MEF in ASP.NET MVC 3<br />Build an IDependencyResolver<br />based on MEF container<br />Use MefContrib<br />ha...
A brief NuGet introduction...<br />Package management system for .NET<br />Simplifies incorporating 3rd party libraries<br...
Using MefContrib<br />And finding it. On NuGet.<br />demo <br />
MefContrib.MVC3<br />Optional addition for MefContrib<br />Adds some things to your application:<br />AppStart code that d...
Conventions in MefContrib-MVC3<br />public class MvcApplicationRegistry : PartRegistry {  public MvcApplicationRegistry() ...
This all makes me think...<br />Package company components using NuGet?<br />Distribute them in a custom feed?<br />Use AS...
Creating application components<br />Initech Default Theme<br />demo <br />
What’s next?<br />Building it<br />MSBuild (or whatever! Nuget.exe is all that matters)<br />Hosting it<br />Create a NuGe...
Let’s see if we can build this...<br />Wiredwith MEF<br />Packagedas .nupkg<br />
Building an application<br />TPS ReportsCover Sheet Generator<br />demo <br />
Conclusion<br />You can build an app like a Lego set<br />Requires “bricks” (NuGet packages)<br />Requires “glue” (MEF / M...
Further information<br />For time travelers:<br />FRM06 – Deconstructing Orchard – Bradley Millington – Lagoon L (Tuesday)...
Thank you for joining     & filling out the evals!<br />Q&A<br />http://blog.maartenballiauw.be<br />@maartenballiauw<br /...
OPN07<br />Fun with ASP.NET MVC 3, MEF and NuGet<br />Maarten Balliauw<br />Technical Consultant<br />RealDolmen<br />@maa...
Upcoming SlideShare
Loading in …5
×

Fun with ASP.NET MVC 3, MEF and NuGet

9,121 views

Published on

So you have a team of developers… And a nice architecture to build on… How about making that architecture easy for everyone and getting developers up to speed quickly? Learn all about integrating the managed extensibility framework (MEF) and ASP.NET MVC with some NuGet sauce for creating loosely coupled, easy to use architectures that anyone can grasp.

Published in: Technology
  • Be the first to comment

Fun with ASP.NET MVC 3, MEF and NuGet

  1. 1.
  2. 2. OPN07<br />Fun with ASP.NET MVC 3, MEF and NuGet<br />Maarten Balliauw<br />Technical Consultant<br />RealDolmen<br />@maartenballiauw<br />
  3. 3. Notes (hidden)<br />So you have a team of developers… And a nice architecture to build on… How about making that architecture easy for everyone and getting developers up to speed quickly? Learn all about integrating the managed extensibility framework (MEF) and ASP.NET MVC with some NuGet sauce for creating loosely coupled, easy to use architectures that anyone can grasp.<br />So what’s this talk about?<br />Show you how you can build an app like Lego<br />Show you how you can create Lego blocks for your team<br />This is NOT a “general recommended approach”, just an idea that proved to work at one of our customers.<br />
  4. 4. Who am I?<br />Maarten Balliauw<br />Antwerp, Belgium<br />www.realdolmen.com<br />Focus on web<br />ASP.NET, ASP.NET MVC, PHP, Azure, …<br />MVP ASP.NET<br />http://blog.maartenballiauw.be<br />@maartenballiauw<br />Me, looking intelligent with glasses<br />
  5. 5. Agenda<br />Technologies & techniques used<br />ASP.NET MVC 3<br />Managed Extensibility Framework (MEF)<br />NuGet<br />Creating application components<br />Building an application<br />Conclusion<br />Further information<br />Q&A<br />
  6. 6. ASP.NET MVC 3<br />All the new stuff:<br />Razor view engine<br />Global Action Filters<br />Unobtrusive Ajax & Client Validation<br />Better Visual Studio tooling<br />And a very interesting one for doing Lego development:<br />Better support for Dependency Injection<br />
  7. 7. var partA =new PartA(new PartB())<br />Sidenote: Dependency Injection?<br />I need a “Part B” !<br />Coming up!<br />Part A<br />Me, doing actual software development<br />
  8. 8. Container<br />Sidenote: Dependency Injection?<br />I need a “Part B” !<br />Let me see...<br />There you go!<br />Part A<br />Part B<br />
  9. 9. How does this fit into ASP.NET MVC 3?<br />ASP.NET MVC 3 uses DependencyResolver<br />: IDependencyResolver<br />GetService()<br />GetServices()<br />Register it on application start<br />
  10. 10. How does this fit in ASP.NET MVC 3?<br />ASP.NET MVC will / can query the IDependencyResolver for<br />Controllers<br />View engines & view pages<br />Filters<br />Model validators<br />Model metadata<br />Check Brad Wilson’s blog for examples on all of these<br />http://bradwilson.typepad.com/blog/2010/07/service-location-pt1-introduction.html <br />Value providers<br />Model binders<br />Controller activator<br />View page activator<br />
  11. 11. Dependency Injection in ASP.NET MVC 3<br />demo <br />
  12. 12. Managed Extensibility Framework (MEF)<br />Cool as ICE: Import, Compose, Export<br />[Import]Ilogger logger;<br />MEF catalog<br />HomeController<br />[Export(typeof(Ilogger)]<br />Let me see...<br />There you go!<br />ConsoleLogger<br />MEF container<br />
  13. 13. Options for MEF in ASP.NET MVC 3<br />Build an IDependencyResolver<br />based on MEF container<br />Use MefContrib<br />has a built-in IDependencyResolver<br />has a “Convention” model<br />is available on NuGet<br />mefcontrib.codeplex.com<br />
  14. 14. A brief NuGet introduction...<br />Package management system for .NET<br />Simplifies incorporating 3rd party libraries<br />Developer focused<br />Free, open source<br />Use packages from the official feed<br />Publish your own packages<br />Create & use your own feed<br />
  15. 15. Using MefContrib<br />And finding it. On NuGet.<br />demo <br />
  16. 16. MefContrib.MVC3<br />Optional addition for MefContrib<br />Adds some things to your application:<br />AppStart code that does the wiring<br />A CompositionDependencyResolver<br />Will check all assemblies in /bin<br />Will export everything : IController by convention<br />
  17. 17. Conventions in MefContrib-MVC3<br />public class MvcApplicationRegistry : PartRegistry { public MvcApplicationRegistry() {<br />Scan(x => {<br />x.Assembly(Assembly.GetExecutingAssembly());x.Directory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"));<br /> });<br /> Part()<br /> .ForTypesAssignableFrom<IController>()<br /> .MakeNonShared()<br /> .ExportTypeAs<IController>()<br /> .ExportType()<br /> .Imports( // ... ); }<br />}<br />
  18. 18. This all makes me think...<br />Package company components using NuGet?<br />Distribute them in a custom feed?<br />Use ASP.NET MVC 3?<br />Wire everything with MEF & MefContrib?<br />Pure application Lego!<br />Me, actually thinking<br />
  19. 19. Creating application components<br />Initech Default Theme<br />demo <br />
  20. 20. What’s next?<br />Building it<br />MSBuild (or whatever! Nuget.exe is all that matters)<br />Hosting it<br />Create a NuGet server<br />Or drop everything in a folder<br />Using it<br />Reference the feed<br />Download & install components needed<br />Assemble using MEF (or another IoC)<br />Install-Package NuGet.Server<br />
  21. 21. Let’s see if we can build this...<br />Wiredwith MEF<br />Packagedas .nupkg<br />
  22. 22. Building an application<br />TPS ReportsCover Sheet Generator<br />demo <br />
  23. 23. Conclusion<br />You can build an app like a Lego set<br />Requires “bricks” (NuGet packages)<br />Requires “glue” (MEF / MefContrib / other IoC)<br />Requires you to think in terms of components<br />Structure is key!<br />Not a best-practice architecture<br />Just something we toyed with on a project<br />Proved to work (for the customer)<br />
  24. 24. Further information<br />For time travelers:<br />FRM06 – Deconstructing Orchard – Bradley Millington – Lagoon L (Tuesday)<br />FRM13 – Scaffolding – Steve Sanderson – Breakers H (Wednesday)<br />Upcoming:<br />FRM09 – NuGetIn Depth – Scott Hanselman & Phil Haack –Lagoon H (now)<br />On the Internet:<br />www.nuget.org<br />mefcontrib.codeplex.com<br />
  25. 25. Thank you for joining & filling out the evals!<br />Q&A<br />http://blog.maartenballiauw.be<br />@maartenballiauw<br />Me, having a question<br />
  26. 26. OPN07<br />Fun with ASP.NET MVC 3, MEF and NuGet<br />Maarten Balliauw<br />Technical Consultant<br />RealDolmen<br />@maartenballiauw<br />
  27. 27. © 2011 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.<br />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.<br />

×