Wednesday, May 14, 2008

Object Oriented design???

As per my understanding following points should be Kept in mind while designing an OO system:

1. Encapsulate what varies: This makes code maintenance easy because by encapsulating what varies we have moved the code more susceptible to changes to one place and it can be modified without affecting the stable code, if needed in future. This way we have introduced low coupling b/w the code which varies and the code which stay same.

2. Program to an interface not an implementation: Stable code is the one which is closed for modification but open for extension. So by programming to an interface or abstraction we can actually modify the actual implementation anytime when required without affecting the code that uses interface. So this way we have flexible and extensible code.

3. Favor composition over inheritance: It allows to delegate some of the responsibilities to the composition objects.This way we can make
changes to composition object implementation independently.

4. Classes should be open for extension but closed for modifications.

There is more to come...

Thursday, May 8, 2008

IQueryable and IQueryProvider

This post by Bart Linq to Active Directory gives good insight of how linq to anything works but it was based on .Net 3.5 Beta1 release and used IQueryable interface because IQueryProvider was introduced while Beta2.

Actually, the IQueryable interface was factored into two interfaces while Beta2 release:

1. IQueryable
2. IQueryProvider

If you use Visual Studio to ‘Go to definition’ you get something that looks like this:

public interface IQueryable : IEnumerable {

Type ElementType { get; }

Expression Expression { get; }

IQueryProvider Provider { get; }

}

public interface IQueryProvider {

IQueryable CreateQuery(Expression expression);

IQueryable CreateQuery(Expression expression);

object Execute(Expression expression);

TResult Execute(Expression expression);

}

Through Linq to Amazon example you can see how it would change the Linq to Active Directory implementation by Bart.

Good resource: Linq to Everything: A List of LINQ Providers


ASP.Net 2.0 Compilation Model

The ASP.NET compiler (aspnet_compiler.exe) was originally introduced in ASP.NET 2.0 as a way of completely precompiling an entire site, making it possible to deploy nothing but binary assemblies (even .aspx and .ascx files are precompiled).
This is compelling because it eliminates any on-demand compilation when requests are made, eliminating the first postdeployment hit seen in some sites today. It also makes it more difficult for modifications to be made to the deployed site (since you can't just open .aspx files and change things), which can be appealing when deploying applications that you want to be changed only through a standard deployment process.
The compiler that ships with the release version of ASP.NET 2.0 supports this binary-only deployment model, but it has also been enhanced to support an updatable deployment model, where all source code in a site is precompiled into binary assemblies, but all .aspx and .ascx files are left basically intact so that changes can be made on the server (the only changes to the .aspx and .ascx files involve the CodeFile attribute being removed and the Inherits attribute being modified to include the assembly name). This model is possible because of the reintroduction of inheritance in the codebehind model, so that the sibling partial classes containing control declarations can be generated and compiled independently of the actual .aspx file class definitions.


So, there are three Deployment Mode; vs2005 deploys a site using updatable mode by default but using aspnet_compiler.exe utility one can use other two option as well that is all source and all binary.

All Source Mode: This mode is generally used while in development phase.

All Binary Mode
When the binary deployment option is used

aspnet_compiler -v /MyWebSite -p "F:\Samples\MyWebSite" "C:\Inetpub\wwwroot\MyWebSite". It results in
1) The .aspx files in the deployment directory, they are just marker files with no content. They have been left there to ensure that a file with the endpoint name is present in case the "Check that file exists" option for the .aspx extension in an IIS app is set.
2) The PrecompiledApp.config file is used to keep track of how the app was deployed and whether ASP.NET needs to compile any files at request time.
3) A precompiled dll which includes all the codebehind files for .aspx(separate assembly per directory) , .ascx(separate assembly per directory) , .master files and App_Code folder.

Updatable (mixed) Mode

To generate the "updatable" site, you would add a -u to the command line, and the resulting .aspx files would contain their original content (and not be empty marker files). Note that this functionality can also be accessed graphically through the Build | Publish Web Site menu item of Visual Studio 2005, as you can see in Figure 5. Both the command-line tool and Visual Studio rely on the ClientBuildManager class of the System.Web.Compilation namespace to provide this functionality.

Deploying a website executing the following command
aspnet_compiler -v /MyWebSite -p "F:\Samples\MyWebSite" -u "C:\Inetpub\wwwroot\MyWebSite"

results in a precompiled dll which includes all the codebehind files for .aspx(separate assembly per directory) , .ascx(separate assembly per directory) , .master files and App_Code folder.


Things to be cautious
Another thing to keep in mind when considering the file-to-assembly mapping is that the use of the internal keyword to prevent external assemblies from accessing methods in your classes may work in some deployment scenarios and not others, because of the different assembly mapping options. Unless you plan ahead of time which deployment option you will be using, it is probably best to avoid internal methods in your pages and stick to the type-scoped protection keywords: public, protected, and private.