S
Steve K.
I am creating several data access objects that all derive from a base class
which implements the web service access functionality.
For example (fake code):
<code>
public class DAOBase
{
protected List<TType> Search<TType>(string nameHint)
{
// code to login to web service session, execute search
// and return the result.
return new List<TType>();
}
}
public class CustomerDAO : DAOBase
{
public List<Customer> GetCustomer(string name)
{
return base.Search<Customer>(name);
}
}
public class OrderDAO : DAOBase
{
public List<Order> GetCustomerOrders(string name)
{
// some code that will execute a search using the DAOBase
// Search method
return null;
}
}
</code>
The web service access exposed in DAOBase is session based and I can only
have one session at a time. In other words, I can't run two searches at the
same time, they must be synchronous.
Once I've logged in (expensive operation) I want to reuse the same session
for all subsequent requests.
I'm thinking of the different ways that I can accomplish this. One idea is
to refactor my code so that my web service functionality is in a new
Singleton class, then the base class would have an instance of this
singleton. This way I could keep my session alive in the singleton and all
concrete objects would access the singleton through the base class.
This would give me thread safety, or, more accurately it won't prevent two
web service requests from being invoked on top of each other. If this
happens, the session will be killed. (bad)
I need to implement a queue to handle the web service request(s) from the
various concrete DAO classes, most likely using the command pattern and
wrapping all request in an object that can be enqueued.
So that is my first and only real idea to solve the issue. Another idea
that is fluttering around in my head is to keep the web service access in
the base class but make the methods static. This will give me the single
session shared with all concrete objects but introduces thread safety issues
(I think).
I would really like to hear what any of you think, before I start modifying
(and breaking) my code all over the place I thought I would ask first to see
if I'm on the right track.
Thanks for any input,
Steve
which implements the web service access functionality.
For example (fake code):
<code>
public class DAOBase
{
protected List<TType> Search<TType>(string nameHint)
{
// code to login to web service session, execute search
// and return the result.
return new List<TType>();
}
}
public class CustomerDAO : DAOBase
{
public List<Customer> GetCustomer(string name)
{
return base.Search<Customer>(name);
}
}
public class OrderDAO : DAOBase
{
public List<Order> GetCustomerOrders(string name)
{
// some code that will execute a search using the DAOBase
// Search method
return null;
}
}
</code>
The web service access exposed in DAOBase is session based and I can only
have one session at a time. In other words, I can't run two searches at the
same time, they must be synchronous.
Once I've logged in (expensive operation) I want to reuse the same session
for all subsequent requests.
I'm thinking of the different ways that I can accomplish this. One idea is
to refactor my code so that my web service functionality is in a new
Singleton class, then the base class would have an instance of this
singleton. This way I could keep my session alive in the singleton and all
concrete objects would access the singleton through the base class.
This would give me thread safety, or, more accurately it won't prevent two
web service requests from being invoked on top of each other. If this
happens, the session will be killed. (bad)
I need to implement a queue to handle the web service request(s) from the
various concrete DAO classes, most likely using the command pattern and
wrapping all request in an object that can be enqueued.
So that is my first and only real idea to solve the issue. Another idea
that is fluttering around in my head is to keep the web service access in
the base class but make the methods static. This will give me the single
session shared with all concrete objects but introduces thread safety issues
(I think).
I would really like to hear what any of you think, before I start modifying
(and breaking) my code all over the place I thought I would ask first to see
if I'm on the right track.
Thanks for any input,
Steve