I have an existing business library that I want to open using the Web API. My existing business classes look like
public class Business
{
public bool DoSomeBusiness()
{
return true;
}
}
I am writing a Web API method, such as the following code, and use asyn / await for better scalability.
public class SampleController : ApiController
{
Business _business;
public ValuesController(Business business)
{
_business = business;
}
public async Task<HttpResponseMessage> Get()
{
var result= await Task.Run(() => _business.DoSomeBusiness());
return Request.CreateResponse(HttpStatusCode.OK, result);
}
}
Is this approach right? Will I really benefit from asynchronous behavior? I do not want to change the existing implementation of the business level to make them task-based.
user4715853
source
share