Hi all,
Background:
I've got a service connection that is limited to 5 logins, (internal app
written in another dept, Java Webservice not WCF compatible.), I've
implemented a library (C# 3.5) that calls this and a number of different
services to provide a coherent data source for our Excel (2003)
applications.
In my dispose, I clean everything up correctly, connections are closed,
webservice is disposed etc.
Problem:
I need to find a way to force the developpers in my team and in the other
teams that use my library to call the Dispose method after each use of the
library.
Is there a pattern or does anyone have an idea, how I can put a limit on how
long the object can be used for?
I can think of some really kludgy ways using elapsed time and throwing an
exception.
Examples:
Good : all calls are closed, webservice is disposed, sockets closed etc.
// Spring.Net
public IPricingService PricingService { private get; set; }
public IEnumerable<IPrice> GetPrices(int ref, DateTime date)
{
using (PricingService)
{
return
PricingService.GetPrices(ref,date,PricingProviders.All);
}
}
Bad : object is not closed, open sockets and the login used for this call
will block until the webservice timeout.
// Spring.Net
public IPricingService PricingService { private get; set; }
public IEnumerable<IPrice> GetPrices(int ref, DateTime date)
{
return
PricingService.GetPrices(ref,date,PricingProviders.All);
}
thanks
Davy,
"Always code as if the guy who ends up maintaining your code will be a
violent psychopath who knows where you live."
- Martin Golding