Skip to content

Prefer passing specific services to constructor instead of IServiceProvider #6016

@Youssef1313

Description

@Youssef1313

We have multiple places where we pass IServiceProvider to constructors. Usually, it's better to make the dependencies very explicit (helps with testability and code clarity as to what exactly a specific component needs).

There might be cases where the service isn't available yet during the constructor, and in these cases we should clearly document that the service is intentionally retrieved later via IServiceProvider because it's not available yet in the constructor.

Today, at least the following classes have IServiceProvider in constrcutor. I didn't validate yet which is valid usage, if any, and which needs to be updated).

  • RetryExecutionFilterFactory
  • HotReloadTestHostTestFrameworkInvoker
  • RetryFailedTestsPipeServer
  • RetryLifecycleCallbacks
  • RetryDataConsumer
  • MSBuildConsumer
  • RetryOrchestrator

Metadata

Metadata

Assignees

Labels

Area: MTPBelongs to the Microsoft.Testing.Platform core library

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions