jueves, noviembre 05, 2009

12 ASP.NET MVC Best Practices

1 – Delete the AccountController

You will never use it and it’s a super-bad practice to keep demo code in your applications.

2 – Isolate Controllers from the outside World

Dependencies on the HttpContext, on data access classes, configuration, logging, clock, etc… make the application difficult (if not impossible) to test, to evolve and modify.

3 – Use an IoC Container

To make it easy to adhere to Best Practice #2, use an IoC Container to manage all that external dependencies. I use Ninject v2, but there are many around, and it’s easy to build your own if needed.

4 – Say NO to “magic strings”

Never use ViewData[“key”], but always create a ViewModel per each View, and use strongly-typed views ViewPage.

Magic strings are evil because they will never tell you whether your view is failing due to a misspelling error, while using a strongly-typed model you will get a compile-time error when there is a problem. And as bonus you get Intellisense.

5 – Build your own “personal conventions”

Use ASP.NET MVC as a base for your (or your company’s) reference architecture. Enforce your own conventions having controllers and maybe views inherit from your own base classes rather then the default ones.

6 – Pay attention to the Verbs

Even without going REST (just RESTful) use the best Http Verb for each action. Adopt the PRG Pattern (Post-Redirect-Get): show data with GET, modify data with POST.

Model’s Best Practices

7 – DomainModel != ViewModel

The DomainModel represents the domain, while the ViewModel is designed around the needs of the View, and these two worlds might be (and usually are) different. Furthermore the DomainModel is data plus behaviours, is hierarchical and is made of complex types, while the ViewModel is just a DTO, flat, and made of strings. To remove the tedious and error-prone object-mapping code, you can useAutoMapper. For a nice overview of the various options I recommend you read: ASP.NET MVC View Model Patterns.

8 – Use ActionFilters for “shared” data

This is my solution for the componentization story of ASP.NET MVC, and might need a future post of its own. You don’t want your controllers to retrieve data that is shared among different views. My approach is to use the Action Filters to retrieve the data that needs to be shared across many views, and use partial view to display them.

View’s Best Practices

9 – Do NEVER user code-behind

NEVER

10 – Write HTML each time you can

I have the option that web developers have to be comfortable writing HTML (and CSS and JavaScript). So they should never use the HtmlHelpers whose only reason of living is hiding the HTML away (likeHtml.Submit or Html.Button). Again, this is something that might become a future post.

11 - If there is an if, write an HtmlHelper

Views must be dumb (and Controllers skinny and Models fat). If you find yourself writing an “if”, then consider writing an HtmlHelper to hide the conditional statement.

12 – Choose your view engine carefully

The default view engine is the WebFormViewEngine, but IMHO it’s NOT the best one. I prefer to use theSpark ViewEngine, since it seems to me like it’s more suited for an MVC view. What I like about it is that the HTML “dominates the flow and that code should fit seamlessly” and the foreach loops and if statements are defined with “HTML attributes”.

Download the slides and demo

Both the slides and the demo code are available for download.


Source: CodeClimbber


lunes, septiembre 07, 2009

12 Tips To Speed-up Your Windows Forms Applications

Recommendations on how to speed up your Windows Forms applications:

  1. Reduce modules loaded by your application to increase start-up time. Remove all references from your project that are not used. Click here to read MSDN article on that on other techniques.
  2. Pre-compile your assemblies using NGEN when appropriate to decrease start-up time. Click here to read my short post with guidelines on when to consider doing this.
  3. Use native C++ Splash Screen that shows up immediately when your application is started. This will make your application appear to load faster. Click here to read and download C++ project with native splash screen. Native splash screens have such small memory footprint that they appear immediately.
  4. Don’t set BackColor=Transparent on your controls. Transparent color support in Windows Forms is terribly inefficient since it is not real transparency. Whenever you set BackColor=Transparent you incur additional Paint call on the parent control. As part of child control rendering, child control will first direct parent control to paint itself on it then child control will paint over that so it appears it is transparent. And this is repeated for every single control that has transparent background. Couple that with the next point and you have real slow-down.
  5. Reduce usage of gradients. Gradients whether linear or radial especially on large surfaces of screen are slow. I know they look good, but use solid colors whenever possible and you will see much better rendering performance. Especially on large panels.
  6. Reduce code in Form Load event. Use BackgroundWorker to offload work onto the different thread so your UI can load faster and feel snappier while you do other work.
  7. Delay Control Creation. Creating and populating controls takes lot of time, so if you can, delay it or do it on demand. For example, you can avoid creating controls on all pages of Tab Control right away and do so in either Appllication.Idle event or when that tab is selected from SelectedTabChanged event.
  8. Set DataSource last. When using data-binding set DataSource property last. If you set it before you set ValueMember or DisplayMemeber properties for bound controls, the data source will be re-queried to populate control each time these properties are set.
  9. Use SuspendLayout and ResumeLayout on parent controls and form to optimize layout changes. Bounds, Size, Location, Visible, and Text for AutoSize controls causes the layout changes. Note that you should call these methods when performing multiple layout changes and always on parent control of the controls that you are changing layout for.
  10. Use BeginUpdate and EndUpdate when adding multiple items to trees, grids and other controls that support this.
  11. Call Dispose() method on your forms once you are done with them. Most of the time developers forget to call Dispose() method on form they’ve shown using ShowDialog(). Make sure you always dispose your forms and controls to free up memory. Use handy using statement.
  12. Dispose() your graphic resources. If you are performing any custom drawing make sure you explicitly dispose your Pen, Brush, Image and other graphic resources once you are done with them. Using statement is good for this as well
Source: DevComponets

viernes, julio 24, 2009

Controles RIA

Muchos controles RIA para todos los gustos!

viernes, julio 17, 2009

Mejorando performance de las paginas web

Yahoo ya hace un tiempo saco YSlow, una herramienta que analizaba nuestra pagina y te recomendaba que buenas practicas seguir, para mejorar la velocidad de nuestra web site. Ahora Google saco PageSpeed. A continuación dejo una pagina de Google plantea por que mejorar la velocidad de toda la web, y links a herramientas para mejorarla, etc.

Algunos Links de SEO

Estoy leyendo de a poco de SEO, dejo a continuación unos links:

martes, junio 23, 2009

Controles Touch para compact framework y MS Sync Framework

Lindos controles en .Net Compact Framework
Demo:
mirabyte Touch Controls 1.0 for .NETCF - Exclusive Preview


  • SyncComm es un proyecto de puntapié inicial, para aprender a usar Sync Services for ADO.NET 1.0 con WCF.


Pizarra de tareas virtual con el mando de la WII

Poco más de 80 dólares hacen falta para tener la pizarra virtual que Johnny Chung Lee construia con el mando de una wii, y y ayer proponía Tommy Norman, emplear con un programa de gestión visual de tareas.

El material necesario es:

En este vídeo Tommy Norman explica el montaje y el resultado.



Fuente: Navegapolis



jueves, abril 23, 2009

Para los que usan mucho la Laptop

Excelente producto! Para la gente que anda continuamente con su laptop.

Es un producto Argentino. Se vende por mercadolibre.

URL: http://dormilaptop.wordpress.com/

lunes, marzo 02, 2009

Asp.net mvc comprimiendo y cache

Dejo un link muy bueno, de como de manera simple, podemos comprimir y usar el cache en asp.net mvc. Tips muy buenos para mejorar la velocidad de nuestro sitio. También dejo como segundo link como usar los ActionFiltersAttributes en los controllers, son como aspectos de los controllers, muy buenos!

Link:
http://weblogs.asp.net/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx

ActionFilterAttribute in ASP.NET MVC Framework




viernes, febrero 20, 2009

Pros y Contras de Linq

Dejo el link a una muy interesante nota sobre Link. Donde el flaco habla de varios pros y contras de Link. La nota tiene links para muchos tips para Linq, y también para muchas contras de Linq. Finalmente la nota termina recomendando la generación de tus objetos (ORM) con PLINQO (Professional LINQ to Objects). Que es un template para CodeSmith.

Nota: Does LINQ StinQ? Not with PLINQO!

Kanban en Software

Unas notas muy interesantes de como usar Kanban en software. Kanban es una metodología que se usa para la manufactura, y para lograr un modelo Just-in-Time. Estas notas aparentemente cuentan como usar la metodología Kanban de producción industrial, en producción de software.

Links:

jueves, febrero 05, 2009

Microsoft Semblio SDK


Microsoft Semblio SDK es sdk justamente, para facilitar la creación de contenido educativo. Todavía no ententiendo bien como funciona. Pero parace fácil, según leo usa .Net y WPF.

Links:
Guia de programacion
Download
Blog

jueves, septiembre 18, 2008

Escribiendo la Sys Layer en Ax 2009

Hoy desarrollando en el trabajo, descubrimos un BUG en Ax 2009. Si, pude escribir en la Sys layer con simples drag and drops.

A continuación pueden ver el video de como reproducirlo.

Si desean bajarlo lo pueden bajar aqui: download Video

martes, septiembre 16, 2008

.Net Model-Driven Development

Encontré dos programas muy interesantes de Model-Driven Development (ambos en beta):

nAML (.NET Application Modeling Language Specification and Tools). Este contiene lógicamente las tools que funcionan con Visio 2003 y también una buena doucumentacion, especificando el modelo, con buenos ejemplos.

URL: http://code.msdn.microsoft.com/naml

Sculpture tiene como interesante que trabaja con varias tecnologias como: DAAB, NHibernate, LINQ, WCF, ASMX, SQL Server, MYSQL..

URL: http://www.codeplex.com/Sculpture

viernes, agosto 15, 2008

12 Tips para escribir Unit Test

Una nota muy piola para conocer rápidamente los principales principios a la hora de escribir test unitarios. Nota: 12 Unit Testing Tips for Software Engineers

Tips:
1. Unit Test to Manage Your Risk
2. Write a Test Case Per Major Component
3. Create Abstract Test Case and Test Utilities
4. Write Smart Tests
5. Set up Clean Environment for Each Test
6. Use Mock Objects To Test Effectively
7. Refactor Tests When You Refactor the Code
8. Write Tests Before Fixing a Bug
9. Use Unit Tests to Ensure Performance
10. Create Tests for Concurrent Code
11. Run Tests Continuously
12. Have Fun Testing!