![Page 1: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/1.jpg)
Architecting, testing and developing an
MVC application
![Page 2: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/2.jpg)
Who I am
• Maxime Rouiller
• ASP.NET/IIS MVP
• 10 years of experience doing web development
• Freelancer
• Twitter: @MaximRouiller
• Blog: http://blog.decayingcode.com
![Page 3: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/3.jpg)
The Plan
• My architecture and its different advantages
• Naming is subjective but must be clear
• How do I start my projects?
• What is the project structure that I use?
• What are my NuGet packages/libraries that I use?
• How do you test MVC Controllers?
![Page 4: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/4.jpg)
3-tier architecture
• Logic or physical architecture?
• Physical:
• Logical:
• MyProject.Web
• MyProject.Infrastructure
• MyProject.Business
![Page 5: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/5.jpg)
Why separate your projects?
• Reusable components can actually be reused.
• Components are more easily testable
• Less likely to screw up (aka: circular references, using the wrong classes, etc.)
![Page 6: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/6.jpg)
Should I separate WebAPI and MVC?
![Page 7: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/7.jpg)
Some rules…
• Just like an onion… you can only depend on the layer bellow
• You can’t use a layer more than one level deep.
• Exception: When binding up a Dependency Injection tool.
![Page 8: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/8.jpg)
My Architecture: Onion/3 tier architecture
Advantages• Easy to understand
• Easy to setup
• Reference rules can easily be enforced by a source control
Disadvantages• Depends on dependency injection
• Is not suited for very complex business logic (see Domain Driven Design)
![Page 9: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/9.jpg)
Architecture is a tool
• If what I suggested doesn’t fit your project, DO NOT USE IT.
• Architecture is a tool. If you only know one, you’ll use it on everything
![Page 10: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/10.jpg)
My Libraries
• Data Access: Entity Framework
• Why not <INSERT TECH HERE>?
• Inversion of Control container: Ninject
• JavaScript? Depends on the project. jQuery/AngularJS
• And more… way more smaller libraries
• Unit Testing: NUnit
• And Azure…
![Page 11: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/11.jpg)
Your Library
• Use anything you feel comfortable!
• Please avoid NHibernate if possible
• Hard to master
• Steep learning curve
• Ensure that it uses NuGet. Why?
![Page 12: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/12.jpg)
DemoCreating some code to test!
Unit testing a controller
Project Structure with tests
Project Structure for scaling with WebAPI
![Page 13: Architecting, testing and developing an mvc application](https://reader035.vdocuments.us/reader035/viewer/2022071901/55c1136fbb61eb5d188b47af/html5/thumbnails/13.jpg)
Questions?
• Contact me on Twitter: @MaximRouiller
• Blog: http://blog.DecayingCode.com
• Add me to LinkedIn
• www.MaximeRouiller.com
• Or speak to me at the break!