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
{
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. Read more: Using Unity Part 1, Part 2, Part 3, Part 4, Part 5, Part 6
{
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.
0 comments:
Post a Comment