tags:

views:

26

answers:

2

I'm redesigning an old VB6 application into VB.net and there is one thing I'm not sure on the best way to do.

In the VB6 application whenever we created a new instance of a component, we would pass in the user details (user name and the like) so we new who was performing the tasks. However, no that I'm redesigning I've created some nice class designs, but I'm having to add in user details into every class and it just looks wrong.

Is there a VB.net way of doing this so my classes can just have class specific details? Some way so that if my classes need to know who is performing a task, they can get the information themselves, rather than having it passed in whenever the objects are created?

A: 

You could put the details of the current user in a class that is accessible by all class instances of your application.

One place you could consider putting it is in the MyApplication class. You could also create a module and place it there.

Alex Essilfie
I did think of that, but my application can be used by more than one user at a time (it's a client/server application that can have 50+ users). How would I know which user's details I was after, without passing in an identifier for that user?
I can't really tell what it is you're doing and what you mean by 'passing in an identifier for that user' but I think you could store the users in a `List` or array. That way, you'd be able to access the users and their ids.
Alex Essilfie
A: 

Could you wrap the current user details into an object, and pass the object when you create the others? They would just keep a reference, and delegate to the user object for user-specific stuff.

That seems like the obvious way?

MarkJ