Any problems with wrapping Task returning method
.net, async-await, c#, task-parallel-library
Solution
As long as the calling code doesn't depend on a member that is avaliable only via `ClassA` and not avaliable via `IClassA`, there shouldn't be a problem.
You are creating and returning a `Cold Task` which will run an async method synchronously which is a waste of resources. You can refactor that code and simply do:
public new async Task<ITspIdentity> FindByIdAsync(string id)
{
var tspIdentity = await base.FindByIdAsync(id).ConfigureAwait(false);
return (ITspIdentity) tspIdentity;
}
Problem
Are there any issues that I might encounter by wrapping a method that returns a ``` Task<T> where T : ClassA ``` with a method that returns a ``` Task<T> where T : IClassA ``` In other words wrapping a method that returns a Task of some type with another method that returns a Task of the interface of that type as below: ``` public new Task<ITspIdentity> FindByIdAsync(string id) { return new Task<ITspIdentity>(() => base.FindByIdAsync(id).Result); } ``` where base.FindByIdAsync(id) would return ``` Task<TspIdentity>. ``` Im having a go at decoupling an ASP.NET MVC applications Presentation tier from a dependency on ASP.Identity by using interfaces.