Best practice in Windows Forms? 
Author Message
 Best practice in Windows Forms?

Hi,

I have

- Framework Layer
- DataAccess Layer
- Rules Layer
- Facade Layer
- WebUI Layer
- WinUI Layer

The user has to log-in to have access to my windows forms app.  I
retrieve a LoginID for that user.  I want that LoginID be accessible
to all layers.  What is the best practice to keep this LoginID
available to all layers?

Regards.

HyperX.



Sat, 11 Jun 2005 02:53:09 GMT  
 Best practice in Windows Forms?
Create a new class on the Framework Layer that will hold the User
Information (including the credentials), for example you can create you own
UserInformation Class that implements  IPrincipal

--
Alberto Borbolla
Microsoft MVP
WebLog:
http://radio.weblogs.com/0114399/


Quote:
> Hi,

> I have

> - Framework Layer
> - DataAccess Layer
> - Rules Layer
> - Facade Layer
> - WebUI Layer
> - WinUI Layer

> The user has to log-in to have access to my windows forms app.  I
> retrieve a LoginID for that user.  I want that LoginID be accessible
> to all layers.  What is the best practice to keep this LoginID
> available to all layers?

> Regards.

> HyperX.



Sat, 11 Jun 2005 03:03:55 GMT  
 Best practice in Windows Forms?


Quote:
> - Framework Layer
> - DataAccess Layer
> - Rules Layer
> - Facade Layer
> - WebUI Layer
> - WinUI Layer

> The user has to log-in to have access to my windows forms app.  I
> retrieve a LoginID for that user.  I want that LoginID be accessible
> to all layers.  What is the best practice to keep this LoginID
> available to all layers?

Interesting one... What about something like...

User u = Security.Login( "tobin", "mypassword" );

//then, in another layer...

if ( Security.UserIsLoggedIn ) {
   int userId = Security.CurrentUser.Id; //just an example

Quote:
}

So, the Security class might look like (note that you may have to make this
thread safe).

public class Security{
    private static _user;
    public static User Login( string username, string password ){
       if ( _user != null ) {
            throw new ApplicationException("cannot login, someones already
in! Use Logout");
       }

        //obviously this would be more sophisticated !!!
        if ( username == "tobin" && password = "mypassword" ){
             _user = new User( 1, "tobin", "adminrole" );//id, name, role
        }
        else {
            throw new ApplicationException("login failed for user " +
username );
         }
    }

    public static void Logout(){ _user = null; }
    public static bool UserIsLoggedIn{ get{ return _user != null; } }
    public static User CurrentUser{ get{ return _user } }
    //etc...

Quote:
}

This is just a general idea. Basically, any layer that has visibility of the
security object can query it for CurrentUser.Id. I'd probably make Security
a Singleton also (search google for 'c# singleton'). You might want to alter
this to handle multiple users?

HTH

Tobin

Quote:
> Regards.

> HyperX.



Sat, 11 Jun 2005 03:40:35 GMT  
 Best practice in Windows Forms?
oops, perhaps using the .NET based stuff would be easier!? I was going to
suggest that you research the framework before starting...

Tobin



Sat, 11 Jun 2005 03:43:51 GMT  
 Best practice in Windows Forms?

Quote:
> Hi,

> I have

> - Framework Layer
> - DataAccess Layer
> - Rules Layer
> - Facade Layer
> - WebUI Layer
> - WinUI Layer

> The user has to log-in to have access to my windows forms app.  I
> retrieve a LoginID for that user.  I want that LoginID be accessible
> to all layers.  What is the best practice to keep this LoginID
> available to all layers?

> Regards.
>> HyperX.

Hi,

You should take a look at "principles".....

Roland



Sat, 11 Jun 2005 04:05:10 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Best Practice - OO

2. Data access 'BEST' practice

3. Best Practices Question - Interacting with VB, C#, C++

4. Advice on best practice for header file organization?

5. Best Practices

6. Software Metrics Best Practices

7. finalizers: best practice

8. Best practices for object serialization?

9. C# Naming Conventions Best Practice?

10. Good practice

11. best practice MDIparent

12. Good programming practices

 

 
Powered by phpBB® Forum Software