Tuesday, April 5, 2011

NuGet Version 1.2 released

Someday ago Phil Haack from Microsoft has released the newer version of Nuget. There will be new exe for the newer version of the NuGet. Those who does not know about NuGet please visit my earlier post about NuGet

Followings are some new features of NuGet 1.2.

  1. Framework profile support
  2. Automatically add binary redirects
  3. Specifying Framework Assembly References (GAC)
  4. Nuget.exe is now able to store API key credentials.
  5. Package Explorer
To know about all the features in details please visit following link.

http://nuget.org/announcements/nuget-1.2-released

You can update to this version via following command.

NuGet.exe u


Shout it
kick it on DotNetKicks.com
Share:
Monday, March 28, 2011

Implementing dependency injection pattern in .NET

Dependency injection pattern is a Software and Architecture designing technique that enables to us to separation of concerns,Modules,Classes and Extensibility of Software Development Project. It enables developer to reduce the complexity of project and you can also add new features to software without modifying whole structures. Let’s first understand how dependency injection is important and why we need it.

Why we need dependency inejction?


Let’s a take two class example of shopping cart. I am having two classes ProductDAL and ProductBLL.Here ProductDAL class represent whole data access Methods while ProductBLL implements whole Business logic in software. In normal scenario what we are doing do we will create a new object ProductDAL classes and then we will use that class for our database operations like below.
Public Class ProducDAL
{
 //Methods for database operations
}

Public Class ProductBLL
{
 ProductDAL objectProductDAL=new ProductDAL();

 //Methods for business logic where we are going to use DAL class
}
As you can see in above scenario we will have tight coupling because here we have created the new object of ProductDAL class and we can only change that if we change the container class ProductBLL. This will not help if we need to extend software after sometime and we need to modify the BLL without modifying existing class.So here comes dependency injection in picture. You can use dependency injection in this kind of scenario.

Ways of implementing Dependency Injection:


There are three ways of implementing dependency injection pattern.
  1. Constructor Injection.
  2. Setter Injection.
  3. Interface base Injection

Constuctor Injection:


In this kind of injection we can use constructor parameters to inject dependencies. Like following.
Interface IDAL
{

}

public class ProductDAL:IDAL
{
 //implement the methods of IDAL
}

public class ProductBLL
{
 private IDAL myDalObject;

 public ProducttBLL(IDAL iDal)
 {
     myDalObject=iDAL;
 }

 //use myDalObject to implement business logic
}
Here you can see in above example I have created a Interface IDAL and that interface contains the all method of Data Access Layer. Now we have ProductDAL class which implements that interface. So now you can create object of ProductBLL class like following.
ProductDAL objProductDAL=new ProductDAL();
PrductBLL objProductBLL=new ProductBLL(objProductDAL);
Here you can see you can pass any class as parameter in ProductBLL class which implements IDAL interface. Its not a concrete object so you can change implementation of ProductDAL class without changing ProductBLL class.

Setter Injection:


In this way we can create public property of Interface and then we can use that property to define the object of ProductDAL class like following.
Public Class ProductBLL
{
 IDAL _myDalObject;

 Pulibc IDAL myDalObject
 {
     get
     {
         return _myDalObject;
     }
     set
     {
         _myDalObject=value;
     }
 }
}
So here you can use property to initialize the ProductDAL class like following.

Infterface Injection:


In this section we can have a Method which will have interface as parameter and that will set object of ProductDAL class.
Public Class PrductBLL
{
 IDAL _myDALObject;

 public IntializeDAL(IDAL dalOjbect)
 {
     _myDALOjbect=dalObject;
 }
}
This is same as constructor injection except that this will intialize object after we call this IntializeDAL method like following.
ProductDAL objProductDAL=new ProductDAL();
PrductBLL objProductBLL=new ProductBLL();
objProductBLL.IntializeDAL(objProductDAL);
Hope you liked it. Stay tuned for more.. Happy programming…

Share:

Three new Action Result Type in ASP.NET MVC 3

In ASP.NET MVC incoming browser request mapped to a controller’s action method and that action method returns type of ActionResult in response to the browsers request. I was playing bit with ASP.NET MVC3 to check out new features of ASP.NET MVC 3 and I have found three great new ActionResult Type. Below is details explanation of each one.

  1. HttpNotFound: This return type returns a error 404 on client. This action result type can be very useful when we have resources that are not found and so we can notify the client with 404 error.
  2. RedirectResult:This returns a temporary redirect code 302 or permanent redirect code 302 depending upon a Boolean flag. This kind of redirection is very important for Search Engine optimization. I have already discussed this feature with asp.net 4.0 here.
  3. HttpStatusCodeResult: Returns a user specified code so developer have choice to return specific error code.

Here are code example of Action ResultType how we can use that in code.

public ActionResult SpecificResult()
{
return new HttpStatusCodeResult(404);
}

public ActionResult NotFound()
{
return HttpNotFound();
}

public ActionResult PermanentRedidrect()
{
return new RedirectResult("http://jalpesh.blogspot.com");
}
Hope you liked it.. Stat tuned for more..Happy Programming
Technorati Tags: ,
Shout it
kick it on DotNetKicks.com
Share:

Support this blog-Buy me a coffee

Buy me a coffeeBuy me a coffee
Search This Blog
Subscribe to my blog

  

My Mvp Profile
Follow us on facebook
Blog Archive
Total Pageviews