Project DescriptionASP.NET MVVM provides a framework to implement the Model-View-ViewModel pattern, a.k.a. the Presentation Model pattern in ASP.NET projects. Developers can take advantages of Dependency Injection and Event Broker to write concise, elegant and business focused code.
The ASP.NET MVVM offers the following benefits:
- Leverage ASP.NET functions, such as web form, user control and data binding
- Achieve a clear separation of concerns
- Facilitate test driven development (TDD)
- Write and maintain simpler code using the attribute annotations
Details
Code Sample1. Create ViewModel in aspx
public partial class _Default : System.Web.UI.Page
{
[Create]
public CustomerController controller { get; set; }
}
2. Reference ViewModel in ascx
public partial class CustomerList : System.Web.UI.UserControl
{
[Inject]
public ICustomerListcontroller {get; set;}
}
3. Subsbribe to events of ViewModel
public partial class CustomerList : System.Web.UI.UserControl
{
[Inject]
public ICustomerList controller {get; set;}
[EventSubscription]
public void CustomerListChanged(object sender, EventArgs e)
{
this.CustomerGridView.DataSource = controller.Customers;
this.CustomerGridView.DataBind();
}
}
4. ViewModel is POCO
public class CustomerController : ICustomerList
{
public event EventHandler CustomerListChanged= delegate {};
public IEnumerable<Customer> Customers {get; set;}
}
Read More about the Design Patterns