Thursday, 12 February 2009

c# 3.0 - Session 2 (Implicitly typed varibles)

Session Overview 2 (Implicitly typed variables)

Local Type Inference (aka Implicitly Typed Local variables)
var keyword
Emphasis on local, as in local scope.

NOTE: var cannot be used in the following cases

As a return value from function
Uninitialized variables
Null assignment

using System;
using System.Collections.Generic;
using System.Linq;

public class csharp3_2
public static void RunSnippet()
var num = 1;
Console.WriteLine("Typeof num is {0}", num.GetType());
var name = "rajesh";
Console.WriteLine("Typeof name is {0}", num.GetType());
string[] countries = new string[] { "India", "US", "Israel", "China"};
var iCountries = from c in countries
where c.StartsWith("I")
select c;
foreach(var c in iCountries)
Console.WriteLine(" Country starting with I {0}", c);

#region Helper methods
public static void Main()
catch (Exception e)
string error = string.Format
("---\nThe following error occurred while executing

the snippet:\n{0}\n---", e.ToString());
Console.Write("Press any key to continue...");

private static void Break()


Session Oveview 2 (Local Type Inference)

Session Oveview 2 (Local Type Inference)

 Local Type Inference (aka Implicitly Typed Local Variable)
 Var keyword (make development easier)
 Emphasis on local, as in local scope.

NOTE: Var keyword works only with local scope.

var first = 1; // first will be of type System.Int32
Console.WriteLine (“Type of first {0}”, first.GetType()):
var name = “rajesh”; // name will be of type System.String
Console.WriteLine (“Type of name {0}”, first.GetType()):

Points to note:
1. var canno be part of a return value of a function.
2. var order; This is invalid as this has to be initialized.
3. var forth = null; This is invalid as null is basically unknown.
Some examples:
String[] countries = new string[]
{“India”, “China”, “Israel”, “Russia”};
// get all countries which starts with “I”
var iCountry = from c in countries
where c.StartsWith(“I”)
select s;
foreach(var country in iCountry)

The output of the above snippet will be

c# 3.0 - Session 1

Session Overview 1 (Auto Implemented Properties)

  • Auto Implemented Properties
  • Prop and propg
Auto Implemented Properties allows you to implement public accessors for your classes private field quickly.

Following is the syntax to declare public accessor for the private field

For shortcut type “prop” and press tab twice.

For e.g. to declare employeeName field use the following shortcut.
public string EmployeeName { get; set; }

For readonly property type “propg” and hit tab twice.
public DateTime OrderDate { get; private set;}

Friday, 8 August 2008

Elements of Application Architecture

The following is the topics that we have to cover as part of "Application Architecture" nirvana session. I am noting these points as it crosses my mind. Will need to add more depth to these points.

- Performance
- Reliability
- Availability
- Security
- Modifiability
- Portability
- Functionality
- Extensibility
- Interoperability
- Usability
- Maintainability
- Efficiecy
- Reusability
- Ease of Deployment
- Rollback strategy
- Configuration Management
- Administration
- Scalability
- Performance/Monitoring
- Development Productivity

The above is what I could think of currently.

Saturday, 26 January 2008

Session 6 - Authentication Module Design

The agenda for today's session was "Forms Authentication". This is in deviation to what was originally planned, but we would like to take things on
priority basis.
The following points will be covered
- What is forms based authentication?
- Relationship between authentication and url authorization module.
- Architecting a custom authentication solution.


We covered how authentication and authorization works in The authentication is handled by the FormsAuthenticationModule and the authorization is handled by the UrlAuthorizationModule. The FAM handles the AuthenticateRequest and EndRequest event. The UrlAuthorizationModule handles the AuthorizeRequestEvent.

The following are the activities that FAM does

- It checks if the request is for login.aspx page
- If yes it sets the SkipAuthorization property to true
- If no it creates the FAC cookie and sets the Principal object
- If does some other activities like extending the ticket timeout value etc.
- The EndRequest checks if the responsecode is 401 and do a redirect to login.aspx if it is else continue serving the request.

The UrlAuthorizationModule essentially checks for incoming URL and verifies if it has access to the resource or not. It checks the authorization element from the configuration and sets the ResponseCode to 0x191, decimal 401 [unauthorized access] if the request does not have access to the requested resource.

Lessons learned:

The following are the lessons learned and could be applied whenever a custom authentication httpmodule is to be developed.
- Handle AuthorizeRequest event to create cookies.
- If you use session as part of authentication, then do session related activities in the AcquireRequestState event.
- If you need to include authorization then follow the standard approach i.e. handle the Authorize event or implement authorization based on the authorization configuration

Enjoy learning

Session 5- Front Controller

In this session we have covered topics related to front controller and how does it relate to the upcoming MVC framework.
The ASP।net framework uses the page controller pattern। Every request is mapped to a page, which interacts with the model and the database.
The Front Controller on the other hands takes all request and dispatches it to appropriate views.

Thursday, 27 December 2007

Session 4 - Coming up...

The agenda for Session 4 is to understand the following Creational Patterns
- Abstract Factory
- Singleton

The idea is to get a working knowledge of the above two patterns and see how we could apply it in real life cases, what problem it solves and how it help keep our design simple and extensible and also elegant.

Stay tuned....