Add dependency injection support to DurableTaskTestHost#613
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds dependency injection support to DurableTaskTestHost, enabling orchestrations and activities to resolve services from a DI container. The implementation provides two approaches: ConfigureServices for simple test scenarios and AddInMemoryDurableTask() for integration with existing hosts.
Changes:
- Added
Servicesproperty toDurableTaskTestHostandConfigureServicesoption toDurableTaskTestHostOptions - Introduced
AddInMemoryDurableTask()extension method for integrating with existing service collections - Created comprehensive test suites demonstrating both DI approaches
- Updated README with detailed documentation and examples
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 15 comments.
Show a summary per file
| File | Description |
|---|---|
| src/InProcessTestHost/DurableTaskTestHost.cs | Added Services property exposing worker host's service provider and ConfigureServices option |
| src/InProcessTestHost/DurableTaskTestExtensions.cs | New extension methods for AddInMemoryDurableTask() and GetInMemoryOrchestrationService() |
| src/InProcessTestHost/README.md | Comprehensive documentation update with examples for both DI approaches |
| test/InProcessTestHost.Tests/DependencyInjectionTests.cs | New test suite for ConfigureServices approach with multiple DI scenarios |
| test/InProcessTestHost.Tests/WebApplicationFactoryIntegrationTests.cs | New test suite for AddInMemoryDurableTask() integration approach |
| test/InProcessTestHost.Tests/WebApplicationFactoryTestHelpers.cs | Test helper types for integration tests |
| Directory.Packages.props | Added package references (currently unused) |
test/InProcessTestHost.Tests/WebApplicationFactoryTestHelpers.cs
Outdated
Show resolved
Hide resolved
test/InProcessTestHost.Tests/WebApplicationFactoryTestHelpers.cs
Outdated
Show resolved
Hide resolved
…rabletask-dotnet into nytian/test-host-di
| public string Status { get; set; } = ""; | ||
| } | ||
|
|
||
| public class UserDto |
There was a problem hiding this comment.
According to coding guidelines, all public classes should have XML documentation comments. These DTO and entity classes are missing XML documentation.
| public string Email { get; set; } = ""; | ||
| } | ||
|
|
||
| public class OrderInput |
There was a problem hiding this comment.
According to coding guidelines, all public classes should have XML documentation comments. These DTO and entity classes are missing XML documentation.
| public int UserId { get; set; } | ||
| } | ||
|
|
||
| public class OrderOutput |
There was a problem hiding this comment.
According to coding guidelines, all public classes should have XML documentation comments. These DTO and entity classes are missing XML documentation.
|
|
||
| public class CalculatorInput | ||
| { | ||
| public int A { get; set; } | ||
| public int B { get; set; } | ||
| } | ||
|
|
||
| public class CalculatorOutput | ||
| { | ||
| public int Sum { get; set; } |
There was a problem hiding this comment.
According to coding guidelines, all public classes should have XML documentation comments. These DTO classes are missing XML documentation.
| public class CalculatorInput | |
| { | |
| public int A { get; set; } | |
| public int B { get; set; } | |
| } | |
| public class CalculatorOutput | |
| { | |
| public int Sum { get; set; } | |
| /// <summary> | |
| /// Represents input values for calculator orchestrator and activity tests. | |
| /// </summary> | |
| public class CalculatorInput | |
| { | |
| /// <summary> | |
| /// Gets or sets the first operand value. | |
| /// </summary> | |
| public int A { get; set; } | |
| /// <summary> | |
| /// Gets or sets the second operand value. | |
| /// </summary> | |
| public int B { get; set; } | |
| } | |
| /// <summary> | |
| /// Represents the calculated results for calculator orchestrator and activity tests. | |
| /// </summary> | |
| public class CalculatorOutput | |
| { | |
| /// <summary> | |
| /// Gets or sets the sum of the input operands. | |
| /// </summary> | |
| public int Sum { get; set; } | |
| /// <summary> | |
| /// Gets or sets the product of the input operands. | |
| /// </summary> |
|
|
||
| public class CalculatorInput | ||
| { | ||
| public int A { get; set; } | ||
| public int B { get; set; } | ||
| } | ||
|
|
||
| public class CalculatorOutput | ||
| { | ||
| public int Sum { get; set; } |
There was a problem hiding this comment.
According to coding guidelines, all public classes should have XML documentation comments. These DTO classes are missing XML documentation.
| public class CalculatorInput | |
| { | |
| public int A { get; set; } | |
| public int B { get; set; } | |
| } | |
| public class CalculatorOutput | |
| { | |
| public int Sum { get; set; } | |
| /// <summary> | |
| /// Represents the input values for calculator operations in tests. | |
| /// </summary> | |
| public class CalculatorInput | |
| { | |
| /// <summary> | |
| /// Gets or sets the first operand. | |
| /// </summary> | |
| public int A { get; set; } | |
| /// <summary> | |
| /// Gets or sets the second operand. | |
| /// </summary> | |
| public int B { get; set; } | |
| } | |
| /// <summary> | |
| /// Represents the results of calculator operations in tests. | |
| /// </summary> | |
| public class CalculatorOutput | |
| { | |
| /// <summary> | |
| /// Gets or sets the sum of the input operands. | |
| /// </summary> | |
| public int Sum { get; set; } | |
| /// <summary> | |
| /// Gets or sets the product of the input operands. | |
| /// </summary> |
3b00579 to
80fff43
Compare
Adds two approaches for dependency injection in
DurableTaskTestHost:WebApplicationFactory)