Understand that Override and New Keywords can help to either implement the base methods or the child methods. But when using the real time examples, I don't see any virtual methods in the following project. Can someone help me to understand why
virtaul
was not used for theBeginTran
method in theServiceBase
Class.- And if making
virtual
base method and usingnew
in derived class implements the base method why there is a call for thebase.BeginTran()
explicitly.
Please help to clarify the doubts.
public sealed class SearchService : ServiceLogic
{
public new SearchService BeginTran()
{
base.BeginTran();
return this;
}
public abstract class ServiceLogic : ServiceBase
{
}
public abstract class ServiceBase : IDisposable
{
public void BeginTran()
{
this.proxy.GetContext().BeginTran();
}
}
Also, the following is my Controller code
using (var svc = new SearchService())
{
return svc.getAll();
}
Calling the Web Service
public sealed class SearchService: ServiceLogic
{
public new SearchService BeginTran()
{
base.BeginTran();
return this;
}
public SearchService Delete(Guid id)
{
Let<User>().Delete(id);
return this;
}
public User GetAll(Guid id)
{
}
So I would like to know why there was a need to call the BeginTran
and return another object of a sealed SearchService
class as earlier we did create an instance using var svc = new SearchService()
.