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
Fun with ASP.NET MVC 3, MEF and NuGet
Maarten BalliauwTechnical ConsultantRealDolmen@maartenballiauw
OPN07
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
Agenda
Technologies & techniques usedASP.NET MVC 3Managed Extensibility Framework (MEF)NuGet
Creating application componentsBuilding an applicationConclusionFurther informationQ&A
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
var partA =new PartA(new PartB())
Sidenote: Dependency Injection?
Part A
I need a “Part B” !
Me, doing actual software development
Coming up!
Container
Sidenote: Dependency Injection?
Part A
I need a “Part B” !
Part B
Let me see...
There you go!
How does this fit into ASP.NET MVC 3?
ASP.NET MVC 3 uses DependencyResolver
: IDependencyResolverGetService()GetServices()
Register it on application start
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
Dependency Injection in ASP.NET MVC 3
demo
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!
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
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
Using MefContrib
And finding it. On NuGet.
demo
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
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( // ... ); }}
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
Creating application components
Initech Default Theme
demo
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
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
Building an application
TPS ReportsCover Sheet Generator
demo
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)
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
Thank you for joining & filling out the evals!
Q&A
Me, having a question
http://blog.maartenballiauw.be @maartenballiauw
Fun with ASP.NET MVC 3, MEF and NuGet
Maarten BalliauwTechnical ConsultantRealDolmen@maartenballiauw
OPN07
© 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.