私は動作していると思われる方法を書いています。 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の上にある抽象化の一部です。我々のフレームワークは、他のコンテナや他のリリースのAutofacにビジネスやその他の依存関係を持つサードパーティのソリューションでも使用できます。プロバイダ固有の内部登録コード。 –