Web Client Software Factory - Model View Presenter - Dependency Injection

The Microsoft Patterns and Practices Group has dropped a very early release of the Web Client Software Factory that you can download from CodePlex.

I say “very early release,” because you won't find any guidance packages in the download like the Data Access Guidance Package and ASMX Guidance Package that I mentioned in the Web Service Software Factory.

Mainly what you will find in the recent release ( Mon Sep 25 2006 ) are examples of the Model View Presenter Pattern that I just talked about here:

The Model View Presenter examples shown tend to use setter injection instead of constructor injection of the model ( controller ) and view into the presenter. I, personally, prefer constructor injection, but that's just me. Here is a snippet from the Web Client Software Factory MVP Example:

 

namespace PresentationLayer
{
    public class CustomerDetailsViewPresenter
    {
        private ICustomersController _controller;

        public ICustomersController Controller
        {
            get { return _controller; }
            set { _controller = value; }
        }

        private ICustomerDetailsView _view;

        public ICustomerDetailsView View
        {
            get { return _view; }
            set { _view = value; OnViewSet(); }
        }

        private void OnViewSet()
        {
            View.ApproveCustomer += new
EventHandler<ApproveCustomerEventArgs>
(_view_ApproveCustomer); } void _view_ApproveCustomer(object sender,
ApproveCustomerEventArgs e) { Controller.ApproveCustomer(e.Id); View.AllowApproveCustomer
= false; ShowCustomer(); } public void OnViewReady() { ShowCustomer(); } private void ShowCustomer() { View.ShowCustomer(Controller.GetCustomer()); } } }

 

You also see some other dependency injection in use, such as the passing of the IAccountDataAccess Service into the business logic modules that use the service, which sets up the unit tests in the project, etc.

 

namespace AccountModule.Implementation
{
    public class AccountServices : IAccountServices
    {
        private IAccountDataAccess _accounts;

        public AccountServices(IAccountDataAccess accounts)
        {
            if (accounts == null)
            {
                throw new ArgumentNullException("accounts");
            }
            _accounts = accounts;
        }
        
        // ...
    }
}

 

If you are interested in the Model View Presenter Pattern and/or just love looking at code like I do, you may enjoy looking at this early drop of the Web Client Software Factory. If you were hoping to see some cool code generation and automation using the Guidance Automation Toolkit, don't bother downloading it yet.

Source: David Hayden ( .NET Developer )

Filed: Web Client Software Factory

 

posted on Friday, September 29, 2006 9:54 PM

Main

News

Green Tea

.NET Development

Enterprise Library

Patterns & Practices