라이브러리의 GetKeyedService(IServiceProvider, Type, Object)에서 GetKeyedServices(IServiceProvider, Type, Object) 및 Microsoft.Extensions.DependencyInjection 메서드의 동작이 KeyedService.AnyKey 등록 처리의 불일치를 해결하기 위해 업데이트되었습니다. 특히 이제 GetKeyedService()를 조회 키로 사용하여 단일 서비스를 확인하려고 할 때 KeyedService.AnyKey 예외를 발생시킵니다. 그리고 GetKeyedServices()(여러 개)는 AnyKey로 쿼리할 때 더 이상 KeyedService.AnyKey 등록을 반환하지 않습니다.
도입된 버전
.NET 10
이전 동작
이전에는 GetKeyedService()를 호출하여 KeyedService.AnyKey에 연결된 AnyKey의 서비스 등록을 반환했습니다. 이 동작은 특정 등록이 아닌 키 지정된 서비스의 특수한 경우를 나타내기 위해 의도된 의미 체계 AnyKey 와 일치하지 않습니다.
GetKeyedServices()와 KeyedService.AnyKey를 호출하여 AnyKey에 대한 모든 등록을 반환합니다. 이 동작은 모든 키 서비스를 열거하기 위한 것이 아니기 때문에 AnyKey 의도한 의미 체계와도 일치하지 않습니다.
새 동작
.NET 10부터 GetKeyedService()를 KeyedService.AnyKey과 함께 호출하면 InvalidOperationException가 발생합니다.
AnyKey는 특정 키가 아닌 특수한 경우를 표현하기 위해 설계되었기 때문에 단일 서비스를 해결하는 데 사용할 수 없습니다.
var service = serviceProvider.GetKeyedService(typeof(IMyService), KeyedService.AnyKey);
// Throws InvalidOperationException: "Cannot resolve a single service using AnyKey."
또한 GetKeyedServices()를 호출할 때 KeyedService.AnyKey가 더 이상 AnyKey에 대한 등록을 반환하지 않습니다. 대신 특별한 경우로 처리되고 서비스를 열거하지 않는 업데이트된 의미 체계 AnyKey 를 준수합니다.
var services = serviceProvider.GetKeyedServices(typeof(IMyService), KeyedService.AnyKey);
// Returns an empty collection.
파괴적 변경 유형
이 변경은 동작 변경입니다.
변경 이유
이전에는 GetKeyedService() 및 GetKeyedServices() 이 KeyedService.AnyKey 와 작동하는 방식이 AnyKey의 의도한 의미와 일치하지 않았습니다. 변경 사항은 AnyKey가 특수한 사례로 처리되고 단일 서비스를 해결하는 데 사용되지 않도록 하기 위하여, 또한 GetKeyedServices()가 AnyKey로 쿼리될 때 AnyKey 등록을 반환하지 않도록 도입되었습니다. 이러한 업데이트는 키 지정된 서비스를 사용할 때 라이브러리 동작의 예측 가능성과 정확성 Microsoft.Extensions.DependencyInjection 을 향상시킵니다. 자세한 내용은 끌어오기 요청 및 연결된 병합 커밋을 참조하세요.
권장 작업
사용 중 GetKeyedService() 또는 GetKeyedServices()을 KeyedService.AnyKey와 함께 사용하는 경우, 코드를 검토하여 AnyKey 대신 특정 키를 사용하도록 업데이트하십시오.
-
GetKeyedService(KeyedService.AnyKey)호출을 특정 키 또는 대체 논리로 바꾸어 서비스 해결을 처리합니다. -
GetKeyedServices(KeyedService.AnyKey)호출을 특정 키로 교체하거나, 검색하려는 서비스만 열거하도록 논리를 업데이트하십시오.
영향을 받는 API
- Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetKeyedService(IServiceProvider, Type, Object)
- Microsoft.Extensions.DependencyInjection.ServiceProviderKeyedServiceExtensions.GetKeyedServices(IServiceProvider, Type, Object)
참고하십시오
.NET