views:

46

answers:

2

Hello,

Thanks for your attention and time. I need your opinion on an basic architectural issue please.

In page behind classes I am using a private and shared object and variables (list or just client or simplay int id) to temporary hold data coming from database or class library. This object is used temporarily to catch data and than to return, pass to some function or binding a control.

1st: Can this approach harm any way ? I couldn't analyze it but a thought was using such shared variables may replace data in it when multiple users may be sending request at a time?

2nd: Please comment also on using such variables in BLL (to hold data coming from DAL/database). In this example every time new object of BLL class will be made.

Here is sample code:

public class ClientManager
{
    Client objclient = new Client();  //Used in 1st and 2nd method
    List<Client> clientlist = new List<Client>();// used in 3rd and 4th method
    ClientRepository objclientRep = new ClientRepository();

    public List<Client> GetClients()
    {
        return clientlist = objclientRep.GetClients();
    }
    public List<Client> SearchClients(string Keyword)
    {
        return clientlist = objclientRep.SearchClients(Keyword);
    }

    public Client GetaClient(int ClientId)
    {
        return objclient = objclientRep.GetaClient(ClientId);
    }

    public Client GetClientDetailForConfirmOrder(int UserId)
    {
        return objclientRep.GetClientDetailForConfirmOrder(UserId);
    }
}

I am really thankful to you for sparing time and paying kind attention.

+3  A: 

If you are creating a new instance of this class for every page refresh, then it won't be a problem as each request will run with its own instances of all the classes.

ck
thanks ck,As I described there are two different situation 1. in page behind class. 2. in class library.In page behind class I am creating new instance of it in class not in some event (above the page load method). In same way in class in BLL.
haansi
+1  A: 

If you are making new instance for each page and functions like GetClients() are heavy you might want to consider not running it for every page/session but use some caching mechanism instead.

On the other way around - if there is only one instance of this class system wide you need synchronization so one thread will not change data while other thread reading it.

Itay
hi Itay,I don't understand how to make new instance of page ?In class I am just creating object before page loads. (it is not in some event) Please guide this way every time is object being re-created ? and for every page request a seprate object will be created ?thanks
haansi
Where do you create the new instance of ClientManager?
Itay