fun with asp.net mvc3, 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
APRIL 12, 2023 | SLIDE 1
APRIL 12, 2023 | SLIDE 2
www.realdolmen.com
FUN WITH ASP.NET MVC 3,MEF AND NUGET
Maarten Balliauw
http://about.me/maartenballiauw
http://blog.maartenballiauw.be
@maartenballiauw
APRIL 12, 2023 | SLIDE 4
WHO AM I?
Maarten Balliauw Antwerp, Belgium www.realdolmen.com Focus on web
ASP.NET MVC, PHP, Azure, SignalR, … MVP Windows Azure (formerly ASP.NET)
Co-founder of AZUG http://blog.maartenballiauw.be @maartenballiauw
Me, looking intelligent with glasses
APRIL 12, 2023 | SLIDE 5
AGENDA
Technologies & techniques used ASP.NET MVC 3 Managed Extensibility Framework (MEF) NuGet
Creating application components Building an application Conclusion Further information Q&A
APRIL 12, 2023 | SLIDE 6
ASP.NET MVC 3
All the new stuff: Razor view engine Global Action Filters Unobtrusive Ajax & Client Validation Better Visual Studio tooling
And a very interesting one for doing LEGO development: Better support for Dependency Injection
APRIL 12, 2023 | SLIDE 7
var partA =new PartA(new PartB())
DEPENDENCY INJECTION?
Part A
I need a “Part B”
!
Me on a typicalwork day
Coming up!
APRIL 12, 2023 | SLIDE 8
Container
DEPENDENCY INJECTION?
Part A
I need a “Part B”
!
Part B
Let me see...
There you go!
APRIL 12, 2023 | SLIDE 9
WHAT ABOUT ASP.NET MVC 3?
ASP.NET MVC 3 uses DependencyResolver
: IDependencyResolver GetService() GetServices()
Register it on application start
APRIL 12, 2023 | SLIDE 10
WHAT ABOUT ASP.NET MVC 3?
ASP.NET MVC will / can query the IDependencyResolver for Controllers View engines & view pages Filters Model validators Model 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 providers Model binders Controller activator View page activator
APRIL 12, 2023 | SLIDE 11
DEPENDENCY INJECTION in ASP.NET MVC 3
APRIL 12, 2023 | SLIDE 12
MANAGED EXTENSIBILITYFRAMEWORK (MEF)
Cool as ICE: Import, Compose, Export
MEF catalogHomeControll
er
[Import]IRule rule;
SomeRuleImpl
[Export(typeof(IRule)]
MEF container
Let me see...
There you go!
APRIL 12, 2023 | SLIDE 13
MEF IN ASP.NET MVC 3
Build an IDependencyResolver based on MEF container
Use has a built-in IDependencyResolver has a “Convention” model is available on NuGet mefcontrib.codeplex.com
APRIL 12, 2023 | SLIDE 14
NUGET
“NuGet is a Visual Studio extension that makes it easy to install and update open source libraries and tools in Visual Studio.”Publish your own packages
Create & use your own feed+
APRIL 12, 2023 | SLIDE 15
USING MEFCONTRIBand finding it on NuGet
APRIL 12, 2023 | SLIDE 16
MEFCONTRIB.MVC3
Optional addition for Adds some things to your application:
AppStart code that does the wiring A CompositionDependencyResolver Will check all assemblies in /bin Will export everything : IController by convention
APRIL 12, 2023 | SLIDE 17
CONVENTIONS BASED MODEL
public class MvcApplicationRegistry : PartRegistry { public MvcApplicationRegistry() { Scan(x => { x.Assembly(Assembly.GetExecutingAssembly()); x.Directory(AppDomain.CurrentDomain.BaseDirectory + "\bin"); });
Part() .ForTypesAssignableFrom<IController>() .MakeNonShared() .ExportTypeAs<IController>() .ExportType() .Imports( // ... ); }}
APRIL 12, 2023 | SLIDE 18
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, thinking
APRIL 12, 2023 | SLIDE 19
CREATING APPLICATION COMPONENTS
APRIL 12, 2023 | SLIDE 20
WHAT’S NEXT?
Building it MSBuild (or whatever! Nuget.exe is all that matters)
Hosting it Create a NuGet server Drop everything in a folder Use a NaaS solution: www.myget.org
Using it Reference the feed Download & install components needed Assemble using MEF (or another IoC)
Install-Package NuGet.Server
APRIL 12, 2023 | SLIDE 21
A QUICK COMMERCIAL PLUG
Create your own NuGet feed Packages from official feed Uploaded/pushed packages No need to setup & maintain your own NuGet Server Free! www.myget.org
APRIL 12, 2023 | SLIDE 22
CREATING A PRIVATE NUGET FEED
APRIL 12, 2023 | SLIDE 23
LET’S SEE IF WE CAN BUILD THIS...
TPS Reports Cover Sheet Generator
(ASP.NET MVC 3)Domain
layer
Domain.TpsReports
Authentication
AccountControllerContracts
And their implementations...
ThemeDefault theme
Packagedas .nupkg
Wiredwith MEF
APRIL 12, 2023 | SLIDE 24
BUILDING AN APPLICATIONCover Sheet Generator
APRIL 12, 2023 | SLIDE 25
CONCLUSION
You can build an app like a Lego set Requires “bricks” (NuGet packages) Requires “glue” (MEF / MefContrib / IoC)
Requires you to think in terms of components Structure is key!
Not a best-practice architecture Just something we toyed with on a project Proved to work (for the customer)
APRIL 12, 2023 | SLIDE 26
FURTHER INFORMATION
On the Internet: www.nuget.org www.myget.org mefcontrib.codeplex.com
APRIL 12, 2023 | SLIDE 27
THANK YOU FOR JOINING
Me, having a question
Maarten Balliauw
http://about.me/maartenballiauw
http://blog.maartenballiauw.be
@maartenballiauw