fun with asp.net mvc 3, mef and nuget
DESCRIPTION
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.TRANSCRIPT
![Page 1: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/1.jpg)
![Page 2: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/2.jpg)
Fun with ASP.NET MVC 3, MEF and NuGet
Maarten BalliauwTechnical ConsultantRealDolmen@maartenballiauw
OPN07
![Page 3: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/3.jpg)
Who am I?
Maarten BalliauwAntwerp, Belgiumwww.realdolmen.com Focus on web
ASP.NET, ASP.NET MVC, PHP, Azure, …MVP ASP.NET
http://blog.maartenballiauw.be @maartenballiauw
Me, looking intelligent with glasses
![Page 4: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/4.jpg)
Agenda
Technologies & techniques usedASP.NET MVC 3Managed Extensibility Framework (MEF)NuGet
Creating application componentsBuilding an applicationConclusionFurther informationQ&A
![Page 5: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/5.jpg)
ASP.NET MVC 3
All the new stuff:Razor view engineGlobal Action FiltersUnobtrusive Ajax & Client ValidationBetter Visual Studio tooling
And a very interesting one for doing Lego development:
Better support for Dependency Injection
![Page 6: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/6.jpg)
var partA =new PartA(new PartB())
Sidenote: Dependency Injection?
Part A
I need a “Part B” !
Me, doing actual software development
Coming up!
![Page 7: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/7.jpg)
Container
Sidenote: Dependency Injection?
Part A
I need a “Part B” !
Part B
Let me see...
There you go!
![Page 8: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/8.jpg)
How does this fit into ASP.NET MVC 3?
ASP.NET MVC 3 uses DependencyResolver
: IDependencyResolverGetService()GetServices()
Register it on application start
![Page 9: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/9.jpg)
How does this fit in ASP.NET MVC 3?
ASP.NET MVC will / can query the IDependencyResolver for
ControllersView engines & view pagesFiltersModel validatorsModel metadata
Check Brad Wilson’s blog for examples on all of these
http://bradwilson.typepad.com/blog/2010/07/service-location-pt1-introduction.html
Value providersModel bindersController activatorView page activator
![Page 10: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/10.jpg)
Dependency Injection in ASP.NET MVC 3
demo
![Page 11: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/11.jpg)
Managed Extensibility Framework (MEF)
Cool as ICE: Import, Compose, Export
MEF catalogHomeController
[Import]Ilogger logger;
ConsoleLogger
[Export(typeof(Ilogger)]
MEF container
Let me see...
There you go!
![Page 12: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/12.jpg)
Options for MEF in ASP.NET MVC 3
Build an IDependencyResolverbased on MEF container
Use MefContribhas a built-in IDependencyResolverhas a “Convention” modelis available on NuGetmefcontrib.codeplex.com
![Page 13: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/13.jpg)
A brief NuGet introduction...
Package management system for .NETSimplifies incorporating 3rd party librariesDeveloper focusedFree, open source
Use packages from the official feedPublish your own packagesCreate & use your own feed
![Page 14: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/14.jpg)
Using MefContrib
And finding it. On NuGet.
demo
![Page 15: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/15.jpg)
MefContrib.MVC3
Optional addition for MefContribAdds some things to your application:
AppStart code that does the wiringA CompositionDependencyResolverWill check all assemblies in /binWill export everything : IController by convention
![Page 16: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/16.jpg)
Conventions in MefContrib-MVC3public class MvcApplicationRegistry : PartRegistry { public MvcApplicationRegistry() { Scan(x => { x.Assembly(Assembly.GetExecutingAssembly()); x.Directory(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin")); });
Part() .ForTypesAssignableFrom<IController>() .MakeNonShared() .ExportTypeAs<IController>() .ExportType() .Imports( // ... ); }}
![Page 17: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/17.jpg)
This all makes me think...
Package company components using NuGet?Distribute them in a custom feed?Use ASP.NET MVC 3?Wire everything with MEF & MefContrib?Pure application Lego!
Me, actually thinking
![Page 18: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/18.jpg)
Creating application components
Initech Default Theme
demo
![Page 19: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/19.jpg)
What’s next?
Building itMSBuild (or whatever! Nuget.exe is all that matters)
Hosting itCreate a NuGet serverOr drop everything in a folder
Using itReference the feedDownload & install components neededAssemble using MEF (or another IoC)
Install-Package NuGet.Server
![Page 20: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/20.jpg)
Let’s see if we can build this...
TPS Reports Cover Sheet Generator (ASP.NET MVC 3)
Domain layer
Domain.TpsReports
Authentication
AccountController
Contracts
And their implementations..
.
Theme
Default theme
Packagedas .nupkg
Wiredwith MEF
![Page 21: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/21.jpg)
Building an application
TPS ReportsCover Sheet Generator
demo
![Page 22: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/22.jpg)
Conclusion
You can build an app like a Lego setRequires “bricks” (NuGet packages)Requires “glue” (MEF / MefContrib / other IoC)
Requires you to think in terms of componentsStructure is key!
Not a best-practice architectureJust something we toyed with on a projectProved to work (for the customer)
![Page 23: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/23.jpg)
Further information
For time travelers:FRM06 – Deconstructing Orchard – Bradley Millington – Lagoon L (Tuesday)FRM13 – Scaffolding – Steve Sanderson – Breakers H (Wednesday)
Upcoming:FRM09 – NuGet In Depth – Scott Hanselman & Phil Haack –Lagoon H (now)
On the Internet:www.nuget.orgmefcontrib.codeplex.com
![Page 24: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/24.jpg)
Thank you for joining & filling out the evals!
Q&A
Me, having a question
http://blog.maartenballiauw.be @maartenballiauw
![Page 25: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/25.jpg)
Fun with ASP.NET MVC 3, MEF and NuGet
Maarten BalliauwTechnical ConsultantRealDolmen@maartenballiauw
OPN07
![Page 26: Fun with ASP.NET MVC 3, MEF and NuGet](https://reader034.vdocuments.site/reader034/viewer/2022052618/554f8cc2b4c9052a518b51ba/html5/thumbnails/26.jpg)
© 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.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.