Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.
ASP.NET MVC - best practices
Bohdan Pashkovskyi
CoreValue
What is ASP .NET MVC is?
This is .NET developers meetup… You should
already know 
Just in case
Delete “Account Controller”
Best practice №1
- You will probably never use these account management pages
- Keeping demo c...
Isolate controllers from the external world
Best practice №2
- HttpContext
- Data Access Classes
- Configuration Managemen...
Use an IoC container
Best practice №3
- StructureMap
- Spring
- Unit
- Windsor
- Ninject
- …
No magic strings
Best practice №4
- Never use ViewData[“key”]
- Never use Request[“key”]
- Always create a ViewModel for e...
Use PRG pattern
Best practice №5
- View sends data in POST
- Controller validates (renders the
View with errors (POST) or
...
DomainModel != ViewModel
Best practice №6
- Domain Model (data + behavior, hierarchical, complex
types)
- View Model (only...
Do not use code behind in Views
Best practice №7
NEVER!!!
Use Bundling and minifying the script and CSS files
Best practice №8
- You should group resources your application needs t...
Use Area
Best practice №9
Cache your data
Best practice №10
- To improve the performance and responsiveness of your
application, you can take advant...
Do not use ASP .NET MVC
Best practice №11
- Here is only 10 best practices
ASP .NET MVC Architecture
Models
Data Access Layer and Repositories
- The purpose of this layer, is the direct access to the
database. It’s the only layer ...
Data Access Layer and Repositories
Service Layer
- What operations do you want to expose your MVC
Controllers? Where is the business logic is going to be
imp...
Service Layer
Presentation Layer
Onion architecture
Repository???
REPOSITORIES ON TOP UNITOFWORK ARE NOT A
GOOD IDEA – ROB CONERY
- WHY NOT?
The Rationale
- This class can’t exist without the SchoolContext – so what
exactly did we decouple here? Nothing.
- In thi...
The Only Thing You Could Do Worse: Repository <T>
- Do You Know Where That DbContext Has Been?
- No, you don’t. It’s getti...
Command/Query Objects
Questions?
Prochain SlideShare
Chargement dans…5
×

sur

ASP .NET MVC - best practices Slide 1 ASP .NET MVC - best practices Slide 2 ASP .NET MVC - best practices Slide 3 ASP .NET MVC - best practices Slide 4 ASP .NET MVC - best practices Slide 5 ASP .NET MVC - best practices Slide 6 ASP .NET MVC - best practices Slide 7 ASP .NET MVC - best practices Slide 8 ASP .NET MVC - best practices Slide 9 ASP .NET MVC - best practices Slide 10 ASP .NET MVC - best practices Slide 11 ASP .NET MVC - best practices Slide 12 ASP .NET MVC - best practices Slide 13 ASP .NET MVC - best practices Slide 14 ASP .NET MVC - best practices Slide 15 ASP .NET MVC - best practices Slide 16 ASP .NET MVC - best practices Slide 17 ASP .NET MVC - best practices Slide 18 ASP .NET MVC - best practices Slide 19 ASP .NET MVC - best practices Slide 20 ASP .NET MVC - best practices Slide 21 ASP .NET MVC - best practices Slide 22 ASP .NET MVC - best practices Slide 23 ASP .NET MVC - best practices Slide 24 ASP .NET MVC - best practices Slide 25 ASP .NET MVC - best practices Slide 26 ASP .NET MVC - best practices Slide 27 ASP .NET MVC - best practices Slide 28
Prochain SlideShare
What to Upload to SlideShare
Suivant
Télécharger pour lire hors ligne et voir en mode plein écran

1 j’aime

Partager

Télécharger pour lire hors ligne

ASP .NET MVC - best practices

Télécharger pour lire hors ligne

ASP .NET MVC - best practices

ASP .NET MVC - best practices

  1. 1. ASP.NET MVC - best practices Bohdan Pashkovskyi CoreValue
  2. 2. What is ASP .NET MVC is? This is .NET developers meetup… You should already know 
  3. 3. Just in case
  4. 4. Delete “Account Controller” Best practice №1 - You will probably never use these account management pages - Keeping demo code in production application is EVIL - Just delete it!
  5. 5. Isolate controllers from the external world Best practice №2 - HttpContext - Data Access Classes - Configuration Management - Logging - Etc… Otherwise - It is not testable application - It is not flexible application
  6. 6. Use an IoC container Best practice №3 - StructureMap - Spring - Unit - Windsor - Ninject - …
  7. 7. No magic strings Best practice №4 - Never use ViewData[“key”] - Never use Request[“key”] - Always create a ViewModel for each view
  8. 8. Use PRG pattern Best practice №5 - View sends data in POST - Controller validates (renders the View with errors (POST) or Redirect in GET - View renders the results in GET
  9. 9. DomainModel != ViewModel Best practice №6 - Domain Model (data + behavior, hierarchical, complex types) - View Model (only data, flat, only strings) - Use AutoMapper
  10. 10. Do not use code behind in Views Best practice №7 NEVER!!!
  11. 11. Use Bundling and minifying the script and CSS files Best practice №8 - You should group resources your application needs to use like CSS files into one downloadable resource. This process is also known as bundling. You should also minify the scripts and CSS files you would use to remove the unnecessary characters, comments and white space characters.
  12. 12. Use Area Best practice №9
  13. 13. Cache your data Best practice №10 - To improve the performance and responsiveness of your application, you can take advantage of caching. Caching is a technique that enables you to store relatively stale data in the memory so as to reduce the network bandwidth consumption.
  14. 14. Do not use ASP .NET MVC Best practice №11 - Here is only 10 best practices
  15. 15. ASP .NET MVC Architecture
  16. 16. Models
  17. 17. Data Access Layer and Repositories - The purpose of this layer, is the direct access to the database. It’s the only layer responsible to communicate with the database. If some other layer wants to access the database, then this will be done through some of the classes (repositories) we will define in this project.
  18. 18. Data Access Layer and Repositories
  19. 19. Service Layer - What operations do you want to expose your MVC Controllers? Where is the business logic is going to be implemented? Yeap.. you have guessed right, in this very layer.
  20. 20. Service Layer
  21. 21. Presentation Layer
  22. 22. Onion architecture
  23. 23. Repository???
  24. 24. REPOSITORIES ON TOP UNITOFWORK ARE NOT A GOOD IDEA – ROB CONERY - WHY NOT?
  25. 25. The Rationale - This class can’t exist without the SchoolContext – so what exactly did we decouple here? Nothing. - In this code, from MSDN, what we have is a reimplentation of LINQ, with the classic problem of the “ever-spiraling Repository API”. By “spiraling API” I mean fun things like “GetStudentByEmail, GetStudentByBirthday, GetStudentByOrderNumber” etc. - But that’s not the primary problem here. The primary problem is the Save() routine. It saves a Student… I think. What else does it save? Can you tell?
  26. 26. The Only Thing You Could Do Worse: Repository <T> - Do You Know Where That DbContext Has Been? - No, you don’t. It’s getting injected and you have no idea which method opened it, nor for what reason. The idea behind Repository is code “reuse” so you’ll probably be calling it from a Registration routine, maybe a new order transaction, or from an API call – who knows? Certainly not your Repository – and this is the main selling point of this pattern!.
  27. 27. Command/Query Objects
  28. 28. Questions?
  • Lokeshreddyrk

    May. 29, 2018

ASP .NET MVC - best practices

Vues

Nombre de vues

320

Sur Slideshare

0

À partir des intégrations

0

Nombre d'intégrations

14

Actions

Téléchargements

10

Partages

0

Commentaires

0

Mentions J'aime

1

×