本文整理汇总了C#中IContainer.ResolveAll方法的典型用法代码示例。如果您正苦于以下问题:C# IContainer.ResolveAll方法的具体用法?C# IContainer.ResolveAll怎么用?C# IContainer.ResolveAll使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IContainer
的用法示例。
在下文中一共展示了IContainer.ResolveAll方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetMappedDataSource
/// <summary>
/// Gets the data source for the specified mapping.
/// </summary>
/// <param name="mapping">The requested mapping.</param>
/// <param name="container">The container.</param>
/// <returns>The data source.</returns>
public static IDataSource GetMappedDataSource(IMapping mapping, IContainer container)
{
mapping = Enforce.NotNull(mapping, () => mapping);
// Depending on the protocol of the mapping, create the appropriate data source. If the
// protocol is not supported, throw an exception.
IDataSource dataSource;
switch (mapping.Protocol)
{
case Protocol.File:
dataSource = new FileDataSource(container, mapping);
break;
case Protocol.Http:
dataSource = new HttpDataSource(container, mapping);
break;
case Protocol.Https:
dataSource = new HttpsDataSource(container, mapping);
break;
case Protocol.Ftp:
dataSource = new FtpDataSource(container, mapping);
break;
default:
throw new ProtocolNotSupportedException(
String.Format(CultureInfo.CurrentCulture,
"The protocol '{0}' is not supported.", mapping.Protocol));
}
// Attach the constraints to the data source.
foreach (ConstraintBase constraint in mapping.Constraints)
{
dataSource.DownloadStarting += constraint.Validate;
}
// Attach the add-ins to the data source.
foreach (var addin in container.ResolveAll<IAddIn>())
{
// Wire up simple events.
dataSource.DownloadStarting += addin.OnDownloadStarting;
dataSource.DownloadFinished += addin.OnDownloadFinished;
// Some events require heavy data load. Wire them only if the event is implemented
// within the add-in.
if(addin.ImplementsOnDownloadVerifying)
{
dataSource.DownloadVerifying += addin.OnDownloadVerifying;
}
}
// Return the data source to the caller.
return dataSource;
}
示例2: ResolveEnumerable
/// <summary>
/// Resolves an enumerable type.
/// </summary>
/// <param name="contractType">The contract type.</param>
/// <param name="container">The container.</param>
/// <returns>A IEnumerable{TContract} instance with all registered instances.</returns>
private static IEnumerable ResolveEnumerable(Type contractType, IContainer container)
{
Type genericArgument = contractType.GetGenericArguments().FirstOrDefault();
object[] resolvedInstances = container.ResolveAll(genericArgument).ToArray();
Type openListType = typeof(List<>);
Type closedListType = openListType.MakeGenericType(genericArgument);
var list = (IList)Activator.CreateInstance(closedListType);
foreach(var instance in resolvedInstances)
{
list.Add(instance);
}
return list;
}
示例3: ResolveArray
/// <summary>
/// Resolves an array type.
/// </summary>
/// <param name="contractType">The contract type.</param>
/// <param name="container">The container.</param>
/// <returns>A TContract[] instance with all registered instances.</returns>
private static Array ResolveArray(Type contractType, IContainer container)
{
Type elementType = contractType.GetElementType();
object[] resolvedInstances = container.ResolveAll(elementType).ToArray();
return resolvedInstances;
}