fluttercommunity / get_it

Get It - Simple direct Service Locator that allows to decouple the interface from a concrete implementation and to access the concrete implementation from everywhere in your App. Maintainer: @escamoteur
https://pub.dev/packages/get_it
MIT License
1.36k stars 149 forks source link

Revise and improve cached factory handling with params #387

Closed ArtAhmetajCR closed 1 month ago

ArtAhmetajCR commented 1 month ago

This Pr references issue #382 where an assertion on the getObject method (and its async equivalent) blocks cached factories from having parameters passed. The fix is adjusting the assertion to include the "cachedFactory" as a type. While fixing this issue I also noticed that the lastParameters were not being saved in the cached factory section, which resulted in the cached factory functions being broken since this check always failed:

if (weakReferenceInstance?.target != null &&
              param1 == lastParam1 &&
              param2 == lastParam2)

Saving the lastParams when creating new instances fixes this.

Appropriate tests have been writen for the cached factory which were entirely missing earlier.

escamoteur commented 1 month ago

@samirsimnica just curious, why could you approve this PR?