internal static IEnumerable <TService> GetServices <TService>(this ServicesContainer services)
        {
            if (services == null)
            {
                throw Error.ArgumentNull("services");
            }

            return(services.GetServices(typeof(TService)).Cast <TService>());
        }
Exemplo n.º 2
0
    /// <summary>
    /// Invoke method
    /// </summary>
    /// <param name="context"></param>
    /// <returns></returns>
    public async Task Invoke(HttpContext context)
    {
        var scontainer = ServicesContainer.GetServices();

        context.Items.Add("DewServiceContainer", scontainer);
        _action?.Invoke(scontainer);
        if (_asyncAction != null)
        {
            await _asyncAction.Invoke(scontainer);
        }
        await _next(context);
    }
Exemplo n.º 3
0
        public void WhenAddingServiceToOverrideThenOriginalIsNotMutated()
        {
            // Handler Services has "copy on write" semantics for inherited list.
            // It can get the inherited list and mutate it.
            ProcessorConfiguration config = new ProcessorConfiguration();
            ServicesContainer      global = config.Services;

            HandlerServices services = new HandlerServices(global);

            IFilterProvider resolver = new Mock <IFilterProvider>().Object;

            // Act
            services.Add(typeof(IFilterProvider), resolver); // appends to end

            // Assert
            IEnumerable <object> original = global.GetServices(typeof(IFilterProvider));

            object[] modified = services.GetServices(typeof(IFilterProvider)).ToArray();

            Assert.True(original.Count() > 1);
            object[] expected = original.Concat(new object[] { resolver }).ToArray();
            Assert.Equal(expected, modified);
        }
        public void Controller_Appends_Inherited_List()
        {
            // Controller Services has "copy on write" semantics for inherited list.
            // It can get the inherited list and mutate it.

            HttpConfiguration config = new HttpConfiguration();
            ServicesContainer global = config.Services;

            ControllerServices cs = new ControllerServices(config.Services);

            ValueProviderFactory vpf = new Mock <ValueProviderFactory>().Object;

            // Act
            cs.Add(typeof(ValueProviderFactory), vpf); // appends to end

            // Assert
            IEnumerable <object> original = global.GetServices(typeof(ValueProviderFactory));

            object[] modified = cs.GetServices(typeof(ValueProviderFactory)).ToArray();

            Assert.True(original.Count() > 1);
            object[] expected = original.Concat(new object[] { vpf }).ToArray();
            Assert.Equal(expected, modified);
        }
 /// <summary>
 /// Get ValueProviderFactories. The order of returned providers is the priority order that we search the factories.
 /// </summary>
 public static IEnumerable <ValueProviderFactory> GetValueProviderFactories(this ServicesContainer services)
 {
     return(services.GetServices <ValueProviderFactory>());
 }
 public static IEnumerable <ModelValidatorProvider> GetModelValidatorProviders(this ServicesContainer services)
 {
     return(services.GetServices <ModelValidatorProvider>());
 }
 public static IEnumerable <IFilterProvider> GetFilterProviders(this ServicesContainer services)
 {
     return(services.GetServices <IFilterProvider>());
 }
 /// <summary>Returns the collection of registered unhandled exception loggers.</summary>
 /// <param name="services">The services container.</param>
 /// <returns>The collection of registered unhandled exception loggers.</returns>
 public static IEnumerable <IExceptionLogger> GetExceptionLoggers(this ServicesContainer services)
 {
     return(services.GetServices <IExceptionLogger>());
 }
Exemplo n.º 9
0
        private static TService[] GetServices <TService>(this ServicesContainer services)
        {
            Contract.Requires(services != null);

            return(services.GetServices(typeof(TService)).Cast <TService>().ToArray <TService>());
        }
Exemplo n.º 10
0
        /// <summary>Returns the collection of registered unhandled exception loggers.</summary>
        /// <param name="services">The services container.</param>
        /// <returns>The collection of registered unhandled exception loggers.</returns>
        public static IEnumerable <IExceptionLogger> GetExceptionLoggers(this ServicesContainer services)
        {
            Contract.Requires(services != null);

            return(services.GetServices <IExceptionLogger>());
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gets the list of <see cref="ModelValidatorProvider"/> service.
        /// </summary>
        /// <param name="services">The <see cref="ServicesContainer"/>.</param>
        /// <returns>The <see cref="ModelValidatorProvider"/> services.</returns>
        /// <exception cref="InvalidOperationException">The <see cref="ModelValidatorProvider"/> services are not registered.</exception>
        public static ModelValidatorProvider[] GetModelValidatorProviders(this ServicesContainer services)
        {
            Contract.Requires(services != null);

            return(services.GetServices <ModelValidatorProvider>());
        }
Exemplo n.º 12
0
        /// <summary>
        /// Gets the list of <see cref="IFilterProvider"/> service.
        /// </summary>
        /// <param name="services">The <see cref="ServicesContainer"/>.</param>
        /// <returns>The <see cref="IFilterProvider"/> services.</returns>
        /// <exception cref="InvalidOperationException">The <see cref="IFilterProvider"/> services are not registered.</exception>
        public static IFilterProvider[] GetFilterProviders(this ServicesContainer services)
        {
            Contract.Requires(services != null);

            return(services.GetServices <IFilterProvider>());
        }
Exemplo n.º 13
0
        /// <summary>
        /// Gets the list of <see cref="IInterceptor"/> service.
        /// </summary>
        /// <param name="services">The <see cref="ServicesContainer"/>.</param>
        /// <returns>The <see cref="IInterceptor"/> services.</returns>
        /// <exception cref="InvalidOperationException">The <see cref="IInterceptor"/> services are not registered.</exception>
        public static IInterceptor[] GetInterceptors(this ServicesContainer services)
        {
            Contract.Requires(services != null);

            return(services.GetServices <IInterceptor>());
        }