How can I create a class interface with async and sync methods?
I'm creating a interface service that implements:
public Interface IService<T> where T : class{
T Get(int id);
bool Add(T entity);
bool Remove(int id);
bool Update(T entity);
}
But some operations in the application context are async methods for instance:
userManager.CreateAsync(user, password)
in the UserManager Class.
And then I do have 2 options.
- use
...GetAwaiter().GetResult();
to make a async call inside a sync method. - Make entire application and my interface async
Tasl<bool> async Add(T entity){ ... }
Both of them are has its owns problem.
...GetAwaiter().GetResult();
can generate some undesired deadlocks as said here- I need to make all methods chain up to be async.
Is possible that interface can provide methods for sync and async methods?