Common Business Module

Topics: CAB & Smart Client Software Factory
Feb 7, 2007 at 9:46 AM
Hi,

I need some guidance on how to develop a business module that can be "plugged in" to many different smart client solutions. Eg. a login business module that is not tied to a spesific solution with a spesific base namespace.

At first glance it seems to me that as long as this business module does not use the action catalog it could be decoupled from the Infrastructure projects that the SCSF creates for you.

Any help would be appreciated.
Thank you
Feb 7, 2007 at 4:04 PM
FWIW,
I create a login project, not a module, just a basic forms project. I use this login project with CAB and non-CAB projects. On the CAB side, I have a service that references this project.

Here is my Authentication Service:
public class PMDPrincipalAuthenticationService : IAuthenticationService
{
    /// <summary>
    /// Keeps track of the # of attempts by the user to login
    /// </summary>
    private int m_attempts = 0;
 
 
    /// <summary>
    /// This is the MAX number of attempts a user gets to login.  I should
    /// move this logic into the AuthMge class, but for now I will leave it
    /// here
    /// </summary>
    private const int MAX_ATTEMPTS = 3;
 
 
    /// <summary>
    /// Authenticates the user.
    /// </summary>
    public void Authenticate()
    {
        //  create a PMDAuthMgr object to show the login form and request credentials.
        //  then check them against the datastore;
        //  For some reason this Authentication method of the CAB isn't a Pass/Fail
        //  if there is a problem, I'm not sure what you are supposed to do.
        AuthMngr authMgr = new AuthMngr();
        bool result = authMgr.ShowLogonForm();
 
        if (result == false)
        {
            throw new AuthenticationException("User cancelled authentication request");
        }
 
        Thread.CurrentPrincipal = authMgr.Principle;
    }
}

In my CabApplication.cs Run() mehtod I call this method:
private void AuthenticateUser()
{
	IAuthenticationService auth = rootWorkItem.Services.Get<IAuthenticationService>(true);
	auth.Authenticate();
}

If the user cancels the authentication process, an exception is thrown and caught in ShellApplication.cs:
[STAThread]
static void Main()
{
    try
    {
        new ShellApplication().Run();
    }
    catch(System.Security.Authentication.AuthenticationException ae)
    {
        Environment.Exit(0);
    }
...

I don't know if that helps you, but it works for me and allows me to have a reusable login/authentication module for my other applications. This is one of the very first things I did when I started with CAB, so it's not the prettiest thing in the world ;)