ScottGu just made available a free downloadable eBook in PDF format as well as a simple and easy-to-understand sample project called Nerddinner. This eBook is actually a chapter from his upcoming book on MVC, but it is an end-to-end tutorial that walks through building a small but complete ASP.NET MVC application from scratch.
This Blog Has A New Home!
Saturday, March 14, 2009
Thursday, March 12, 2009
C# 3.0 Automatic Properties
OK, so better later than never! Somehow I missed the automatic properties feature of C# 3.0, and just discovered it while I was reading up on something unrelated. It’s a nice feature of C# 3.0 that saves you a few key strokes hence enhances developer productivity as well as allows for more clear and concise code.
Using this new feature, instead of defining private variables and creating explicit getters and setters, you can create properties like this:
Wednesday, March 11, 2009
Free Visual Studio 2008 Productivity Add-in
Developer Express and Microsoft provide a new version of CodeRush licensed exclusively for C# developers working in Visual Studio. The new product is called CodeRush Xpress, and it includes a slew of useful features to boost your productivity under Visual Studio.
Friday, August 17, 2007
The Castle Project
In the last couple of years I have noticed a steadily growing interest in the .NET community around the Inversion of Control (IoC) and Dependency Injection (DI) patterns. This is partly due to the fact that a number of excellent frameworks have emerged and gained popularity that allow us to use these designs in our applications relatively painlessly. One such framework is the open source Castle Project. In my opinion Castle is the best implementation of IoC and DI among many others that I have come across including Spring.NET, NInject, and ObjectBuilder. This is however my opinion; which framework you use largely depends upon your requirements and your preferences.
If you are just getting started with Castle or are curious about why the heck one should use IoC and DI, I strongly suggest you check out the 3-part article series by Simone Busoli. I just came across these articles and I can't stress enough how well they are written.
Wednesday, April 18, 2007
SQL Server Database Comparison and Synchronization
Since database are usually designed in development environments, migrating changes over to other environments (e.g. QA and production) is not a trivial task. This is because SQL Server does not have any built-in tools to compare database schemas.
There are quite a few third-party tools that would make your life easier, most notably, Red Gate's SQL Compare (reasonably priced around $300).
At times, buying a commercial tool is not really an option, so one must resort to googling for free tools. There are three such tools that I am aware of:
- SQLDBDiff by SQLDBTools
A very decent tool that comes in both freeware and shareware versions. Freeware version is not badly crippled; only advanced features such as multi-database comparison, data content comparison, etc. are disabled.
- Database Schema Comparison Utility
This is a Code Project article that comes with C# source code of a schema comparison utility. The utility itself is pretty bare-bone, but gets the job done.
- StarInix Free Database Compare 2.0
I have not used this tool, but from the advertised feature list, it looks pretty good. Most notably, in addition to SQL Server, this tool works with Access and MySQL databases.
Tuesday, February 06, 2007
JScript Eval Method In C#
JavaScript and JScript languages provide a convenient Eval method that allows for dynamic evaluation of expressions. This functionality can be duplicated in C# using Microsoft's JScript CodeDomProvider and Reflection. Following class automatically compiles an in-memory assembly using JScript CodeDomProvider. The Eval method uses this assembly to dynamically evaluate specified expressions:
Using this class, we can execute statements such as:
Sunday, December 10, 2006
Using IXmlSerializable To Overcome "not expected" Error On Derived Classes
Monday, October 02, 2006
.NET 2.0: On-demand Configuration Encryption
Thursday, September 14, 2006
Adding Controls To ASP.NET GridView Pager Row
ASP.NET GridView And Conditional Images
Wednesday, September 13, 2006
Enumerating Cache Items
Saturday, September 09, 2006
ADO.NET Calculated Columns
Sunday, August 27, 2006
DIP: Dependency Inversion Principle
Essentially what this principle means is that in a tiered design, higher level modules and lower level modules should not directly depend on each other; instead they should only depend on abstractions. Moreover, abstractions should not have any knowledge of details (other classes in the system). This principle closely relates to some of the other design principles I discussed previously in that it yields a design that is highly decoupled ensuring that minor changes in one part of the application do not cause a domino effect in other parts of the application. Moreover such a design is extensible -- as new business entities are added, usually such as design scales well by requiring only new code to be added rather than existing code to be modified. ASP.NET 2.0's Provider Model is a great example of such a design that provides a default implementation for various sub-systems such as Membership, Personalization, Navigation, etc. but also allows developers to modify the default behavior by extending certain classes.
- High-level modules should not depend on low-level modules. Both should depend on abstractions.
- Abstractions should not depend on details. Details should depend on abstractions.
Wednesday, August 23, 2006
LSP: Liskov Substitution Principle
Let q(x) be a property provable about objects x of type T. Then q(y) should be true for objects y of type S where S is a subtype of T.What it means is that if S is a subtype of T, then a function q(x) must behave in the same manner irrespective of the type of x whether it be S or T. In other words, if a piece of code behaves differently for a subtype than a supertype, then that code violates the LSP (and consequently the OCP). Let's say that we work for a bank and that we have a simple teller application. Currently the teller application works with checking and savings account types. Our bank just entered the mortgage business so we need to modify our teller application to support this new account type. During the short analysis phase we decide that since mortgage account is type of an account (IS-A relationship), we can simply create a new mortgage class deriving from the Account abstract class, override a method and a property, and we should be in business. We add a new class as follows: Everything sounds logical, that is until we come across this code in the teller application: Based on our pre-existing code, the ReceiveMoney() method is making a reasonable assumption that the new balance should be equal to the old balance plus the newly deposited amount. This assumption is, however, violated if we pass an instance of the Mortgage class to this method. This is a clear violation of the LSP.
Monday, August 21, 2006
OCP Open-Closed Principle
Software entities (classes, modules, functions, etc.) should beEssentially, what this means is that software's design should be such that it's behavior can be modified by extending the existing source code rather than modifying it. Consider the following example: Notice that the ReceiveMoney() method of the Bank class has to determine the type of account passed in. Only based on that information it can perform the appropriate business logic. Later if we add another account type then we may need to modify this code in order for it to work properly. The above code is, hence, in violation of the Open-Closed principle. So how can we revise our code to conform to the Open-Closed Principle? Abstraction is the answer. Let's take a look: Notice how we got rid of all conditional logic in the ReceiveMoney() method. Also notice that if we later add a new account type, the ReceiveMoney() method will work without any modifications. The revised version of our code above, hence, conforms to the Open-Closed Principle. Let's now consider what happens to our code if a new business rule is added that requires an e-mail notification to be sent to the account holder whenever a deposit is made. Obviously, we'll have to modify the ReceiveMoney() method to perform that logic. Since we can't account for all possible scenarios, we can never acheive perfect closure. With that in mind, design the simplest software that will do the job, and conform to OCP or other such design principles where you see the need.
open for extension, but closed for modification.