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.
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;
}
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