Click here to Skip to main content
15,896,606 members
Articles / Desktop Programming / Win32

Model View Presenter Using Dependency Injection and Threading Support

Rate me:
Please Sign up or sign in to vote.
4.73/5 (30 votes)
8 Jan 2008CPOL16 min read 113.9K   977   143  
How to code the MVP pattern using Spring.Net.
using System;
using System.Collections.Generic;
using System.Text;

namespace MvpExample
{

   public class LogonService : ILogonService
   {
      private INotify mNotifier;
      public LogonService()
      {
         // instead of having it as null
         mNotifier = new EmptyNotify(); 
      }
      public LogonService(INotify notifier)
      {
         mNotifier = notifier;
      }
      public bool Logon(string userName, string password)
      {
         // simulate a long operation, wait 3 seconds.
         System.Threading.Thread.Sleep(TimeSpan.FromSeconds(5));

         bool rc;
         if ((userName == "mike") && (password == "aop"))
         {
            mNotifier.Notify("Logon Successful");
            rc = true;                       
         }
         else
         {
            mNotifier.Notify("Invliad User or Password");
            rc = false;            
         }

         return rc;
      }
      public INotify Notifier
      {
         set { mNotifier = value; }
         get { return mNotifier; }
      }
   }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
I am currently working as a team leader with a group of amazing .NET programmers. I love coding with .NET, and I love to apply design patterns into my work. Lately I had some free time, so I decided to write some articles, hoping I will spare someone frustration and anxiety.

Comments and Discussions