architecting, testing and developing an mvc application

13
Architecting, testing and developing an MVC application

Upload: maxime-rouiller

Post on 05-Aug-2015

41 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Architecting, testing and developing an mvc application

Architecting, testing and developing an

MVC application

Page 2: Architecting, testing and developing an mvc application

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

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

3-tier architecture

• Logic or physical architecture?

• Physical:

• Logical:

• MyProject.Web

• MyProject.Infrastructure

• MyProject.Business

Page 5: Architecting, testing and developing an mvc application

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

Should I separate WebAPI and MVC?

Page 7: Architecting, testing and developing an mvc application

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

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

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

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

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

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

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!