A good blog talking about unit test XAML data bindings -
http://csharperimage.jeremylikness.com/2010/08/unit-testing-xaml-data-bindings-in.html
Store this for future reference. :)
Monday, March 21, 2011
Wednesday, March 2, 2011
my MVC 3 journey
Went to Seattle last week to attend a very cool workshop. Exposed to many new terms, technologies and tools used in a demo project. Summarize some of them as below:
1) Razor (cshtml) - Wondering why we no longer saw any aspx files in that project, but only cshtml files. Well, welcome to the new Razor world. Did more reading about Razor afterwards. It looks very neat and compact. Here is one of the best blogs about Razor for beginners - Introducing "Razor" – a new view engine for ASP.NET from Scott Gu.
2) EF Code First - the coolest thing about this is that - you don't need to create database or tables beforehand. When you run your application first time, if it cannot find the database and the tables, it will create them based on your classe model definitions. Like a magic! Of course, you would need to wire the db connection in the web.config file. Further more, if you make changes to any classes (add / remove properties), you can also wire the application to allow drop and recreate the database in the Application_Start() event using "DbDatabase.SetInitializer". For sure, this only makes sense in the testing / development environment, where losing data is not an issue. One more tip, you can override default data types by using System.Data.Entity.ModelConfiguration, and method OnModelCreating().
3) Validation - The validations in MVC 3 look much simplier and less code comparing to what we are using right now. Microsoft takes care of both the client-side and server-side (in case the JavaScript is disabled in user's browser) validations for you. All you need to do is to add the decorations above your class properties like this - [Required(ErrorMessage = "This field XXXXX is required")]. Availabel built-in validations include "Required", "StringLength", "Range"... Cool!
4) QUnit - how can you do unit test if all the logics are moved into JavaScript. Qunit or Jasmine are used in the demo. Having tools like these is an absolute step-up in the JavaScript world.
Finally, here is the link to talk about all the related technlogies included in this project Announcing release of ASP.NET MVC 3, IIS Express, SQL CE 4, Web Farm Framework, Orchard, WebMatrix , again from Scott Gu.
This is one of the best workshops. Feeling smarter now. ;)
1) Razor (cshtml) - Wondering why we no longer saw any aspx files in that project, but only cshtml files. Well, welcome to the new Razor world. Did more reading about Razor afterwards. It looks very neat and compact. Here is one of the best blogs about Razor for beginners - Introducing "Razor" – a new view engine for ASP.NET from Scott Gu.
2) EF Code First - the coolest thing about this is that - you don't need to create database or tables beforehand. When you run your application first time, if it cannot find the database and the tables, it will create them based on your classe model definitions. Like a magic! Of course, you would need to wire the db connection in the web.config file. Further more, if you make changes to any classes (add / remove properties), you can also wire the application to allow drop and recreate the database in the Application_Start() event using "DbDatabase.SetInitializer". For sure, this only makes sense in the testing / development environment, where losing data is not an issue. One more tip, you can override default data types by using System.Data.Entity.ModelConfiguration, and method OnModelCreating().
3) Validation - The validations in MVC 3 look much simplier and less code comparing to what we are using right now. Microsoft takes care of both the client-side and server-side (in case the JavaScript is disabled in user's browser) validations for you. All you need to do is to add the decorations above your class properties like this - [Required(ErrorMessage = "This field XXXXX is required")]. Availabel built-in validations include "Required", "StringLength", "Range"... Cool!
4) QUnit - how can you do unit test if all the logics are moved into JavaScript. Qunit or Jasmine are used in the demo. Having tools like these is an absolute step-up in the JavaScript world.
Finally, here is the link to talk about all the related technlogies included in this project Announcing release of ASP.NET MVC 3, IIS Express, SQL CE 4, Web Farm Framework, Orchard, WebMatrix , again from Scott Gu.
This is one of the best workshops. Feeling smarter now. ;)
Saturday, January 15, 2011
a good blog about generic and constrain it with "where"
James M. Hare's blog about constraining generics with "where" clause
The blog is thorough. Store it for future reference.
To summarize some key syntaxs as below:
- constrains to an interface or a base class
public class MyClass<T> where T : IMyInterface<T>
- constrains to reference type
where T : class
- Constrain to value type
where T : struct
- Constrain to required consturctor
Where T: class, new()
"Basically, the where clause allows you to specify additional constraints on what the actual type used to fill the generic type placeholder must support." In another word, "if the type meets the given constraint, you can perform the activities that pertain to that constraint with the generic placeholders."
This empowers you to write less code across types. Less is more.
Saturday, January 8, 2011
.Net 4.0 Framework and Lazy<T> - when lazier gets better
Found a couple good blogs abouot Lazy<T> in the new .Net 4.0 framework.
http://sankarsan.wordpress.com/2009/10/04/laziness-in-c-4-0-lazyt/
http://weblogs.asp.net/gunnarpeipman/archive/2009/05/19/net-framework-4-0-using-system-lazy-lt-t-gt.aspx
The key points are:
- When you create a new object, you no longer do "MyClass = new MyClass();". Instead, you do "Lazy<MyClass> = new Lazy<MyClass>();".
- For classes with no parameterless constructor, you need to do below
new Lazy<Pet>(delegate() { return new Pet("DuDu", "Siberian Husky"); });
- The Lazy<T> will NOT instantiate the instance until its value is accessed.
- Its default mode is NOT thread safe.
However, you can make it threadsafe by doing below constructors:
1) public Lazy(LazyExecutionMode mode)
2) public Lazy(Func<T> valueFactory,LazyExecutionMode mode)
What is the big gain here? Well, you no longer need to write your own code to implement the laziness as you did in .Net 3.5, or earlier. Instead, the constructor helps you to implement the lazy loading.
Is it cool to be lazier but get the same thing done.
http://sankarsan.wordpress.com/2009/10/04/laziness-in-c-4-0-lazyt/
http://weblogs.asp.net/gunnarpeipman/archive/2009/05/19/net-framework-4-0-using-system-lazy-lt-t-gt.aspx
The key points are:
- When you create a new object, you no longer do "MyClass = new MyClass();". Instead, you do "Lazy<MyClass> = new Lazy<MyClass>();".
- For classes with no parameterless constructor, you need to do below
new Lazy<Pet>(delegate() { return new Pet("DuDu", "Siberian Husky"); });
- The Lazy<T> will NOT instantiate the instance until its value is accessed.
- Its default mode is NOT thread safe.
However, you can make it threadsafe by doing below constructors:
1) public Lazy(LazyExecutionMode mode)
2) public Lazy(Func<T> valueFactory,LazyExecutionMode mode)
What is the big gain here? Well, you no longer need to write your own code to implement the laziness as you did in .Net 3.5, or earlier. Instead, the constructor helps you to implement the lazy loading.
Is it cool to be lazier but get the same thing done.
Saturday, December 11, 2010
a nice blog about Class Level Model Validation
Scott Gu's blog about Class Level Model Validation -
http://weblogs.asp.net/scottgu/archive/2010/12/10/class-level-model-validation-with-ef-code-first-and-asp-net-mvc-3.aspx
This is cool. Save it for future reference.
http://weblogs.asp.net/scottgu/archive/2010/12/10/class-level-model-validation-with-ef-code-first-and-asp-net-mvc-3.aspx
This is cool. Save it for future reference.
Subscribe to:
Posts (Atom)