evolutionary-architecture / evolutionary-architecture-by-example

Navigate the complex landscape of .NET software architecture with our step-by-step, story-like guide. Unpack the interplay between modular monoliths, microservices, domain-driven design, and various architectural patterns. Go beyond the one-size-fits-all solutions and understand how to blend these approaches based on your unique needs.
MIT License
1.55k stars 191 forks source link

fix: get rid of call build service provider multiple times during feature flag resolving #103

Closed kamilbaczek closed 5 months ago

kamilbaczek commented 5 months ago

🔧 PR Includes:

Fixed feature flag resolving mechanism during startup. The previous version used the build service provider on the main dependency injection container, resulting in dependencies being built multiple times, which caused issues in singleton services. (Reference: https://medium.com/@damien.vandekerckhove/why-you-shouldnt-call-buildserviceprovider-in-net-development-8e25f680d529)

The issue arises when the feature flag is resolved in the ServiceCollection part.

🛠️ Changes Made:

Implemented a new approach that creates a dedicated service provider, which is disposed of right away when the application's dependencies are registered. This new provider only contains dependencies that are used for feature flag resolution, thus isolating it from causing issues in other dependencies.