작동하는 것으로 보이는 방법을 작성했습니다. Autofac에서이 작업을 수행 할 수있는 방법이 있다면 의견을 보내 주시면 감사하겠습니다. 아래 예제에서 _context 필드는 IComponentContext 유형입니다.
여기에 가장 좋은 옵션은 키와 정기적으로 '입력'서비스를 모두 사용하여 항목을 등록하는 것입니다
public IEnumerable<T> ResolveAll<T>()
{
// We're going to find each service which was registered
// with a key, and for those which match the type T we'll store the key
// and later supplement the default output with individual resolve calls to those
// keyed services
var allKeys = new List<object>();
foreach (var componentRegistration in _context.ComponentRegistry.Registrations)
{
// Get the services which match the KeyedService type
var typedServices = componentRegistration.Services.Where(x => x is KeyedService).Cast<KeyedService>();
// Add the key to our list so long as the registration is for the correct type T
allKeys.AddRange(typedServices.Where(y => y.ServiceType == typeof (T)).Select(x => x.ServiceKey));
}
// Get the default resolution output which resolves all un-keyed services
var allUnKeyedServices = new List<T>(_context.Resolve<IEnumerable<T>>());
// Add the ones which were registered with a key
allUnKeyedServices.AddRange(allKeys.Select(key => _context.ResolveKeyed<T>(key)));
// Return the total resultset
return allUnKeyedServices;
}
빠른 응답에 이어 OP에서 지연된 응답은 매우 선전하지 않습니다. 거대한 사과! 내 질문에 반드시 모든 등록을 통제 할 필요는 없다고 언급 했어야했다. 이것은 사이트를 구축하는 데 사용되는 프레임 워크 (Umbraco 5)에서 Autofac 위에있는 추상화의 일부입니다. 우리 프레임 워크는 다른 컨테이너 나 다른 Autoofac에 대한 비즈니스 또는 다른 의존성을 가진 타사 솔루션에서 사용할 수 있습니다. 공급자 고유의 내부 등록 코드 –