-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
design-smellDesign issues which aren't breaking but need to be fixedDesign issues which aren't breaking but need to be fixedenhancementNew feature or requestNew feature or request
Description
ViewModelFactory::GetViewModel, which has several overloads, is implemented as a synchronous method. However, it makes a call to IDataStore<Resource>::GetOne which is an asynchronous method. It forces this call to be blocking by accessing the .Result property of the Task returned from the call to GetOne. This can lead to deadlocks and other performance issues.
It's easy enough to change GetViewModel to be async, but it will cause ripples through the codebase (as going fully asynchronous usually does).
Proposed steps:
- Change
GetViewModeloverloads to beasync- this is actually the easy part. It differs slightly per overload, but it will be easy enough to go make each of them async. - Change all callers to expect GetViewModel calls to be async - this is the harder part, let's dig into why. First,
GetViewModelis actually just a backing implementation for a bunch ofFunc<T, VM>factory methods that get registered into the services collection at start up. I actually like this, it's an elegant way to abstract the caller from how the view models are resolved without the need to introduce your own factory interface (love me someFunc<>). Now, what would need to happen to propagate the asynchronous behavior is as follows:
a. All of theseFunc<T, VM>would now need to becomeFunc<T, Task<VM>>instead.
b. All dependents who are expecting these to be injected would match that previous signature change
c. All dependents need to be updated toawaitthe result of the factory method instead of expecting it synchronously.
d. Any dependent methods that were previously synchronous will also have to be updated to beasync.
e. Any callers of dependent methods ofdnow need toawaitthose methods and if they themselves were synchronous, now go to stepdagain for its dependents and rinse and repeat until you get all the way to the top.
So it's a bunch of menial work which will not only ensure that you benefit from the asynchronous nature of the underlying call, but, more importantly, ensure you don't end up in a deadlock situation.
Metadata
Metadata
Assignees
Labels
design-smellDesign issues which aren't breaking but need to be fixedDesign issues which aren't breaking but need to be fixedenhancementNew feature or requestNew feature or request