CQRSalad.Dispatching.ServiceProviderExtensions.GetInterceptors C# (CSharp) Method

GetInterceptors() static private method

static private GetInterceptors ( this serviceProvider, IEnumerable interceptorsTypes ) : List
serviceProvider this
interceptorsTypes IEnumerable
return List
        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;
        }
    }
ServiceProviderExtensions