This is a mirror of official site: http://jasper-net.blogspot.com/

Using Unity

| Sunday, May 9, 2010
I have been going through implementing some IoC pattern using Unity and so I decided to share my learnings (I know that’s not an English word, but you get the point). Ok, so I have an ASP.net project named ProductWeb and a class library called ProductModel. In the model library, I have a class called Product:

public class Product
{

public string Name { get; set; }
public string Description { get; set; }

public Product()
{

Name = "iPad";
Description = "Not just a reader!";
}

public string WriteProductDetails()
{

return string.Format("Name: {0} Description: {1}", Name, Description);
}
}

In the Page_Load event of the default.aspx, I’ll need something like:

  1: Product product = new Product();
  2: productDetailsLabel.Text = product.WriteProductDetails();

Now, let’s go ‘Unity’fy this application. I assume you have all the bits for the pattern. If not, get it from here. I found this schematic representation of Unity pattern from the above link.

UnityConfigurationSchema_thumb_45410C99.png

Read more: Using Unity Part 1, Part 2, Part 3, Part 4, Part 5, Part 6

Posted via email from jasper22's posterous

0 comments: