I have a class (called Employee. non static) defined in a class library. I am instantiating that class in another project and calling some methods.
Is it okay to write a Dispose method in that class? The reason I wanted to write custom dispose method because I am calling a webservice inside Employee class.
public class Employee
{
SoapSample company = new SoapSample();
public Employee()
{
company.UserCredentials.UserName = "";
company.UserCredentials.Password = "";
}
}
The web service client should be stateless anyway, I'd expect. What unmanaged resources would you want to dispose? Sounds like you don't need it.
EDIT: It feels like an odd design for an Employee type to have a reference to a soap client to start with, to be honest. Are you sure this is an appropriate design?
You could just implement the IDisposable interface
public class Employee : IDisposable
{
SoapSample company = new SoapSample();
public Employee()
{
company.UserCredentials.UserName = "";
company.UserCredentials.Password = "";
}
public void Dispose()
{
//TODO:put your cleanup code here
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With