Feature/add dependency injection#80
Conversation
|
/AzurePipelines run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR adds dependency-injection support for ForgeAction instantiation by introducing an extensible IForgeActionFactory and wiring TreeWalkerSession to use it, while preserving the legacy Activator.CreateInstance behavior by default.
Changes:
- Introduced
IForgeActionFactoryplus default (DefaultForgeActionFactory) and DI-backed (ServiceProviderActionFactory) implementations. - Added
ActionFactorytoTreeWalkerParametersand updatedTreeWalkerSessionto instantiate actions via the configured factory. - Added DI-focused unit tests and test actions, and updated test project dependencies accordingly.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Forge.TreeWalker/src/TreeWalkerSession.cs | Uses Parameters.ActionFactory for action instantiation and sets a default factory when none is provided. |
| Forge.TreeWalker/src/TreeWalkerParameters.cs | Adds ActionFactory configuration surface for consumers. |
| Forge.TreeWalker/src/IForgeActionFactory.cs | Defines the factory abstraction for action creation. |
| Forge.TreeWalker/src/DefaultForgeActionFactory.cs | Provides backwards-compatible action creation using Activator.CreateInstance. |
| Forge.TreeWalker/src/ServiceProviderActionFactory.cs | Adds a DI-based factory using ActivatorUtilities. |
| Forge.TreeWalker/Forge.TreeWalker.csproj | Adds DI abstractions package needed by ServiceProviderActionFactory. |
| Forge.TreeWalker.UnitTests/test/DependencyInjectionTests.cs | Adds unit tests validating default factory behavior, DI factory behavior, and custom factory behavior. |
| Forge.TreeWalker.UnitTests/test/ActionsAndCallbacks/DependencyInjectionTestAction.cs | Adds test actions and test service types to validate constructor injection scenarios. |
| Forge.TreeWalker.UnitTests/Forge.TreeWalker.UnitTests.csproj | Adds DI package references and includes new test source files. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
@microsoft-github-policy-service agree company="Microsoft" |
TravisOnGit
left a comment
There was a problem hiding this comment.
Chatted offline. Approved! Please update wiki pages so folks know how to use Dependency Injection in Forge.
https://github.com/microsoft/Forge/wiki/How-To:-Use-Forge-in-my-Application#TreeWalkerParameters
https://github.com/microsoft/Forge/wiki/How-To:-Author-a-ForgeAction - I'm thinking either add a new section at the bottom with a DI example, or maybe right after "BaseAction Inheritance" section. The goal is to give the reader a good flow of information for maximum absorption.
This pull request introduces support for dependency injection in Forge by adding an extensible factory mechanism for creating ForgeAction instances. It allows consumers to plug in their own dependency injection containers (such as Microsoft.Extensions.DependencyInjection) for action instantiation. The default behavior is preserved for backward compatibility. The changes are accompanied by new unit tests and test actions to verify DI integration.
Dependency Injection Support in ForgeAction Creation:
IForgeActionFactoryinterface, which defines a factory for creating ForgeAction instances. This enables integration with DI containers.DefaultForgeActionFactory(usesActivator.CreateInstance) for backward compatibility, andServiceProviderActionFactoryfor integration with Microsoft.Extensions.DependencyInjection. [1] [2]ActionFactoryproperty toTreeWalkerParameters, allowing consumers to specify a custom factory. If not set, the default factory is used.TreeWalkerSessionto use the configuredIForgeActionFactoryfor all ForgeAction instantiation, centralizing and simplifying the creation logic. [1] [2]Dependency Injection Test Coverage:
SingleDependencyAction,MultipleDependencyAction, etc.) and unit tests to verify that dependency injection works as expected with ForgeActions. [1] [2] [3]These changes make Forge extensible and compatible with modern dependency injection patterns, while maintaining existing behavior for users who do not require DI.