internal static List<IContextInterceptor> GetInterceptors(this IServiceProvider serviceProvider, IEnumerable<Type> interceptorsTypes)
{
List<IContextInterceptor> interceptorsInstances;
try
{
interceptorsInstances = interceptorsTypes.Select(serviceProvider.GetService)
.Cast<IContextInterceptor>()
.ToList();
}
catch (Exception exception)
{
throw new ServiceProviderException("An exception ocurred during creating interceptors. See the inner exception for details.", exception);
}
if (!interceptorsInstances.Any() || interceptorsInstances.Any(x => x == null))
{
throw new ServiceProviderException("ServiceProvider couldn't create interceptor.");
}
return interceptorsInstances;
}
}