Contracts between services
Install packages:
ServiceContract lets you manage your service responses more quickly.
Easy return:
public class MyController : ControllerBase
{
//...
[HttpPost]
public async Task<MessageContract<long>> Add(CreateFaqRequestContract request)
{
//Do stuff
return 1452;
}
}
Easy cast:
public class MyController : ControllerBase
{
//...
[HttpPost]
public async Task<MessageContract<long>> Add(CreateFaqRequestContract request)
{
MessageContract<string> serviceResult = //service stuff;
if (!serviceResult)
return serviceResult.ToContract<long>();
//Do stuff
return 1452;
}
}
Easy convert:
public class MyController : ControllerBase
{
//...
[HttpPost]
public Task<MessageContract<long>> Add(CreateFaqRequestContract request)
{
Task<MessageContract<string>> serviceResult = //service stuff;
return serviceResult.ToContract(x => long.Parse(x));
}
}
Easy error:
public class MyController : ControllerBase
{
//...
[HttpPost]
public async Task<MessageContract<long>> Add(CreateFaqRequestContract request)
{
return (FailedReasonType.NotFound, "Service result not found!");
}
}