Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash related to the avatar service dependency (PSG-1140) #7268

Merged
merged 3 commits into from
Jan 16, 2023

Conversation

alfogrillo
Copy link
Contributor

@alfogrillo alfogrillo commented Jan 13, 2023

A crash is being reported in the DependencyContainer which wasn't able to resolve the AvatarServiceProtocol.

This PR refactors the code by changing the dependency injection mechanism for the AvatarServiceProtocol.
In particular now the AvatarViewModel is injected in an AvatarImage by using SwiftUI's environment objects.

This architecture is still flexible enough to allow injection of a mocked avatar service.

Since we used the custom DependencyContainer DI mechanism just for this case, I deleted it completely from the project.

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@alfogrillo alfogrillo requested review from a team and Anderas and removed request for a team January 13, 2023 12:36
@alfogrillo alfogrillo changed the title Fix avatar service dependency crash (PSG-1140) Fix crash related to the avatar service dependency (PSG-1140) Jan 13, 2023
@codecov
Copy link

codecov bot commented Jan 13, 2023

Codecov Report

Base: 11.85% // Head: 11.83% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (3696e38) compared to base (3284437).
Patch coverage: 43.07% of modified lines in pull request are covered.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #7268      +/-   ##
===========================================
- Coverage    11.85%   11.83%   -0.02%     
===========================================
  Files         1628     1624       -4     
  Lines       160325   160296      -29     
  Branches     65507    65518      +11     
===========================================
- Hits         19001    18977      -24     
+ Misses      140685   140680       -5     
  Partials       639      639              
Flag Coverage Δ
uitests 54.85% <71.79%> (-0.04%) ⬇️
unittests 5.97% <0.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ommon/Avatar/Service/MatrixSDK/AvatarService.swift 0.00% <ø> (ø)
...es/Common/InfoSheet/MockInfoSheetScreenState.swift 0.00% <0.00%> (ø)
...dinator/LiveLocationSharingViewerCoordinator.swift 0.00% <0.00%> (ø)
...aring/Coordinator/LocationSharingCoordinator.swift 0.00% <0.00%> (ø)
...Coordinator/StaticLocationViewingCoordinator.swift 0.00% <0.00%> (ø)
...rdinator/RoomNotificationSettingsCoordinator.swift 0.00% <0.00%> (ø)
...cationSettings/View/RoomNotificationSettings.swift 0.00% <0.00%> (ø)
...Settings/View/RoomNotificationSettingsHeader.swift 0.00% <0.00%> (ø)
...omUpgrade/Coordinator/RoomUpgradeCoordinator.swift 0.00% <0.00%> (ø)
...estion/Coordinator/UserSuggestionCoordinator.swift 0.00% <0.00%> (ø)
... and 41 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

Copy link
Contributor

@Anderas Anderas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to use environmentObject as native solution in SwiftUI for this, though I am generally cautions when it comes to this type of dependency injection (compared to say initializer dependency injection) - it is all too easy to forget it at one place, causing a crash. It sounds good for mocks and previews though

@alfogrillo alfogrillo merged commit 2d3eee0 into develop Jan 16, 2023
@alfogrillo alfogrillo deleted the alfogrillo/fix_avatar_service_crash branch January 16, 2023 11:17
@alfogrillo alfogrillo mentioned this pull request Jan 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants