Skip to content

feat: [#667] Optimize dependency order#1102

Merged
hwbrzzl merged 3 commits intomasterfrom
bowen/#667-1
Jun 30, 2025
Merged

feat: [#667] Optimize dependency order#1102
hwbrzzl merged 3 commits intomasterfrom
bowen/#667-1

Conversation

@hwbrzzl
Copy link
Contributor

@hwbrzzl hwbrzzl commented Jun 30, 2025

📑 Description

Closes goravel/goravel#667

Previously, there is an issue if a provider didn't set a relationship.

image

This pull request introduces enhancements to the foundation/application.go file by improving the handling of service provider dependencies and bindings, as well as adding comprehensive test cases to validate these changes. The most significant updates include the introduction of virtual bindings for providers without explicit bindings, improved dependency graph construction, and new test scenarios to ensure correctness and robustness.

Enhancements to service provider dependency handling:

  • Virtual bindings for providers without explicit bindings: Added logic to create virtual bindings for service providers that lack explicit bindings but have dependencies or "provide-for" relationships. This ensures these providers are included in the dependency graph. (foundation/application.go)
  • Improved dependency graph construction: Enhanced the sorting logic to account for virtual bindings and ensure providers are sorted in a valid topological order. This includes changes to how dependencies and "provide-for" relationships are processed. (foundation/application.go) [1] [2]

Debugging and testing improvements:

  • Debugging support: Added a call to debug.Dump to output the configured service providers for easier debugging. (foundation/application.go)
  • New test scenarios for edge cases: Introduced multiple test cases to validate scenarios such as circular dependencies, empty bindings with dependencies or "provide-for" relationships, and unidirectional dependencies. (foundation/application_test.go) [1] [2] [3]
  • Topological order validation: Added a helper function isTopologicalOrder to ensure that the sorted providers maintain a valid topological order. This is used in test cases to verify correctness. (foundation/application_test.go)

These changes improve the robustness and maintainability of the service provider sorting mechanism, ensuring proper handling of complex dependency scenarios while providing better debugging and testing capabilities.

✅ Checks

  • Added test cases for my code

for _, provider := range providers {
if !used[provider] {
sortedProviders = append([]foundation.ServiceProvider{provider}, sortedProviders...)
sortedProviders = append(sortedProviders, provider)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The providers that don't set a relationship will be set to the bottom.

@codecov
Copy link

codecov bot commented Jun 30, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 71.15%. Comparing base (6e7dea0) to head (574f157).
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1102      +/-   ##
==========================================
+ Coverage   71.09%   71.15%   +0.06%     
==========================================
  Files         185      185              
  Lines       13183    13213      +30     
==========================================
+ Hits         9372     9402      +30     
  Misses       3441     3441              
  Partials      370      370              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@hwbrzzl hwbrzzl marked this pull request as ready for review June 30, 2025 08:43
@hwbrzzl hwbrzzl requested a review from a team as a code owner June 30, 2025 08:43
@hwbrzzl hwbrzzl merged commit ae80591 into master Jun 30, 2025
14 checks passed
@hwbrzzl hwbrzzl deleted the bowen/#667-1 branch June 30, 2025 09:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Registering service providers don't dependent order

1 participant