Commit ffa829e
authored
Fix FieldClearMap service registration issue causing runtime error (#3005)
The `FieldClearMap` was causing a runtime error when users tried to use
it in their field mapping configuration:
```
System.InvalidOperationException: No service for type 'MigrationTools.FieldMaps.AzureDevops.ObjectModel.FieldClearMap' has been registered.
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider provider, Type serviceType)
at MigrationTools.Tools.FieldMappingTool..ctor(IOptions`1 options, IServiceProvider services, ILogger`1 logger, ITelemetryLogger telemetry)
```
This occurred when users configured the field map in their migration
settings:
```json
{
"FieldMapType": "FieldClearMap",
"ApplyTo": ["Feature"],
"targetField": "System.Description"
}
```
The issue was that while the `FieldClearMap` class was fully implemented
and documented, it was missing from the dependency injection service
registration in the
`AddMigrationToolServicesForClientLegacyAzureDevOpsObjectModel` method.
## Root Cause
The `FieldMappingTool` resolves field maps from the DI container using
`Services.GetRequiredService(type)`, but `FieldClearMap` was not
registered as a transient service like other field maps.
## Changes
- Added `context.AddTransient<FieldClearMap>();` to the service
registration in `ServiceCollectionExtensions.cs`
- Added test coverage for `FieldClearMapOptions` configuration
- Added service registration test to verify DI container resolution
## Impact
Users can now successfully use the FieldClearMap functionality that was
already documented and implemented but previously inaccessible due to
the missing service registration.
<!-- START COPILOT CODING AGENT SUFFIX -->
<details>
<summary>Original prompt</summary>
>
> ----
>
> *This section details on the original issue you should resolve*
>
> <issue_title>[Bug]:</issue_title>
> <issue_description>### Version
>
> - [x] I confirm that I am using the latest version
>
> ### Source Version
>
> Azure DevOps Service
>
> ### Target Version
>
> Azure DevOps Service
>
> ### Relevant configuration
>
> ```shell
> {
> "FieldMapType": "FieldClearMap",
> "ApplyTo": [
> "Feature"
> ],
> "targetField": "System.Description"
> }
> ```
>
> ### Relevant log output
>
> ```shell
> Unhandled exception!
> System.InvalidOperationException: No service for type
'MigrationTools.FieldMaps.AzureDevops.ObjectModel.FieldClearMap' has
been registered.
> at
Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetRequiredService(IServiceProvider
provider, Type serviceType)
> at MigrationTools.Tools.FieldMappingTool..ctor(IOptions`1 options,
IServiceProvider services, ILogger`1 logger, ITelemetryLogger telemetry)
in D:\a\1\s\src\MigrationTools\Tools\FieldMappingTool.cs:line 48
> ```
>
> ### What happened?
>
> I am trying to use the _FieldClearMap_ to clear the Description field
for migrated work items. I get the error `'No service for type
'MigrationTools.FieldMaps.AzureDevops.ObjectModel.FieldClearMap' has
been registered.'` and then the migrator quits without migrating the
work item.
>
> ### Debug in Visual Studio
>
> - [x] Visual Studio Debug</issue_description>
>
> ## Comments on the Issue (you are @copilot in this section)
>
> <comments>
> </comments>
>
</details>
Fixes #3002
<!-- START COPILOT CODING AGENT TIPS -->
---
💬 Share your feedback on Copilot coding agent for the chance to win a
$200 gift card! Click
[here](https://survey3.medallia.com/?EAHeSx-AP01bZqG0Ld9QLQ) to start
the survey.File tree
3 files changed
+46
-0
lines changed- src
- MigrationTools.Clients.TfsObjectModel.Tests/Tools
- MigrationTools.Clients.TfsObjectModel
- MigrationTools.Tests/Tools/FieldMaps
3 files changed
+46
-0
lines changedLines changed: 22 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| 85 | + | |
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
| |||
Lines changed: 23 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
0 commit comments