-
Notifications
You must be signed in to change notification settings - Fork 53
Add dependency injection support to DurableTaskTestHost #613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Copilot reviewed 7 out of 7 changed files in this pull request and generated 31 comments.
| public class User | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } = ""; | ||
| public string Email { get; set; } = ""; | ||
| } | ||
|
|
||
| public class Order | ||
| { | ||
| public int Id { get; set; } | ||
| public int UserId { get; set; } | ||
| public decimal Amount { get; set; } | ||
| public string Status { get; set; } = ""; | ||
| } | ||
|
|
||
| public class UserDto | ||
| { | ||
| public int Id { get; set; } | ||
| public string Name { get; set; } = ""; | ||
| public string Email { get; set; } = ""; | ||
| } | ||
|
|
||
| public class OrderInput | ||
| { | ||
| public int OrderId { get; set; } | ||
| public int UserId { get; set; } | ||
| } | ||
|
|
||
| public class OrderOutput |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to coding guidelines, all private classes that do not serve as base classes should be sealed. These test helper classes (User, InMemoryUserRepository, InMemoryOrderRepository, UserService, OrderService, PaymentService) do not serve as base classes and should be marked as sealed for better performance and clarity.
| public class User | |
| { | |
| public int Id { get; set; } | |
| public string Name { get; set; } = ""; | |
| public string Email { get; set; } = ""; | |
| } | |
| public class Order | |
| { | |
| public int Id { get; set; } | |
| public int UserId { get; set; } | |
| public decimal Amount { get; set; } | |
| public string Status { get; set; } = ""; | |
| } | |
| public class UserDto | |
| { | |
| public int Id { get; set; } | |
| public string Name { get; set; } = ""; | |
| public string Email { get; set; } = ""; | |
| } | |
| public class OrderInput | |
| { | |
| public int OrderId { get; set; } | |
| public int UserId { get; set; } | |
| } | |
| public class OrderOutput | |
| public sealed class User | |
| { | |
| public int Id { get; set; } | |
| public string Name { get; set; } = ""; | |
| public string Email { get; set; } = ""; | |
| } | |
| public sealed class Order | |
| { | |
| public int Id { get; set; } | |
| public int UserId { get; set; } | |
| public decimal Amount { get; set; } | |
| public string Status { get; set; } = ""; | |
| } | |
| public sealed class UserDto | |
| { | |
| public int Id { get; set; } | |
| public string Name { get; set; } = ""; | |
| public string Email { get; set; } = ""; | |
| } | |
| public sealed class OrderInput | |
| { | |
| public int OrderId { get; set; } | |
| public int UserId { get; set; } | |
| } | |
| public sealed class OrderOutput |
| User? GetById(int id); | ||
| } | ||
|
|
||
| public class InMemoryUserRepository : IUserRepository |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to coding guidelines, all private classes that do not serve as base classes should be sealed. These test helper classes (User, InMemoryUserRepository, InMemoryOrderRepository, UserService, OrderService, PaymentService) do not serve as base classes and should be marked as sealed for better performance and clarity.
| void Update(Order order); | ||
| } | ||
|
|
||
| public class InMemoryOrderRepository : IOrderRepository |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to coding guidelines, all private classes that do not serve as base classes should be sealed. These test helper classes (User, InMemoryUserRepository, InMemoryOrderRepository, UserService, OrderService, PaymentService) do not serve as base classes and should be marked as sealed for better performance and clarity.
| UserDto? GetUser(int id); | ||
| } | ||
|
|
||
| public class UserService : IUserService |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to coding guidelines, all private classes that do not serve as base classes should be sealed. These test helper classes (User, InMemoryUserRepository, InMemoryOrderRepository, UserService, OrderService, PaymentService) do not serve as base classes and should be marked as sealed for better performance and clarity.
| void UpdateStatus(int id, string status); | ||
| } | ||
|
|
||
| public class OrderService : IOrderService |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to coding guidelines, all private classes that do not serve as base classes should be sealed. These test helper classes (User, InMemoryUserRepository, InMemoryOrderRepository, UserService, OrderService, PaymentService) do not serve as base classes and should be marked as sealed for better performance and clarity.
| public string Status { get; set; } = ""; | ||
| } | ||
|
|
||
| public class UserDto |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; } |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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; } |
Copilot
AI
Jan 16, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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> |
Adds two approaches for dependency injection in
DurableTaskTestHost:WebApplicationFactory)