Esempio n. 1
0
        public MvcEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            MvcEndpointInvokerFactory invokerFactory,
            IEnumerable <IActionDescriptorChangeProvider> actionDescriptorChangeProviders,
            IServiceProvider serviceProvider)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            if (actionDescriptorChangeProviders == null)
            {
                throw new ArgumentNullException(nameof(actionDescriptorChangeProviders));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            _actions         = actions;
            _invokerFactory  = invokerFactory;
            _serviceProvider = serviceProvider;
            _actionDescriptorChangeProviders = actionDescriptorChangeProviders.ToArray();

            _endpoints = new List <Endpoint>();
            ConventionalEndpointInfos = new List <MvcEndpointInfo>();
        }
Esempio n. 2
0
        public MvcEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            MvcEndpointInvokerFactory invokerFactory,
            IEnumerable <IActionDescriptorChangeProvider> actionDescriptorChangeProviders)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            if (actionDescriptorChangeProviders == null)
            {
                throw new ArgumentNullException(nameof(actionDescriptorChangeProviders));
            }

            _actions        = actions;
            _invokerFactory = invokerFactory;
            _actionDescriptorChangeProviders = actionDescriptorChangeProviders.ToArray();

            _endpoints = new List <Endpoint>();

            InitializeEndpoints();
        }
Esempio n. 3
0
        private MvcEndpointDataSource CreateMvcEndpointDataSource(
            IActionDescriptorCollectionProvider actionDescriptorCollectionProvider = null,
            MvcEndpointInvokerFactory mvcEndpointInvokerFactory = null,
            IEnumerable <IActionDescriptorChangeProvider> actionDescriptorChangeProviders = null)
        {
            if (actionDescriptorCollectionProvider == null)
            {
                var mockDescriptorProvider = new Mock <IActionDescriptorCollectionProvider>();
                mockDescriptorProvider.Setup(m => m.ActionDescriptors).Returns(new ActionDescriptorCollection(new List <ActionDescriptor>(), 0));

                actionDescriptorCollectionProvider = mockDescriptorProvider.Object;
            }

            var serviceProviderMock = new Mock <IServiceProvider>();

            serviceProviderMock.Setup(m => m.GetService(typeof(IActionDescriptorCollectionProvider))).Returns(actionDescriptorCollectionProvider);

            var dataSource = new MvcEndpointDataSource(
                actionDescriptorCollectionProvider,
                mvcEndpointInvokerFactory ?? new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty <IActionInvokerProvider>())),
                actionDescriptorChangeProviders ?? Array.Empty <IActionDescriptorChangeProvider>(),
                serviceProviderMock.Object);

            return(dataSource);
        }
Esempio n. 4
0
        public MvcEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            MvcEndpointInvokerFactory invokerFactory)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            _actions        = actions;
            _invokerFactory = invokerFactory;

            ConventionalEndpointInfos = new List <MvcEndpointInfo>();

            // It's possible for someone to override the collection provider without providing
            // change notifications. If that's the case we won't process changes.
            if (actions is ActionDescriptorCollectionProvider collectionProviderWithChangeToken)
            {
                ChangeToken.OnChange(
                    () => collectionProviderWithChangeToken.GetChangeToken(),
                    UpdateEndpoints);
            }
        }
Esempio n. 5
0
        private MvcEndpointDataSource CreateMvcEndpointDataSource(
            IActionDescriptorCollectionProvider actionDescriptorCollectionProvider = null,
            MvcEndpointInvokerFactory mvcEndpointInvokerFactory = null)
        {
            if (actionDescriptorCollectionProvider == null)
            {
                actionDescriptorCollectionProvider = new DefaultActionDescriptorCollectionProvider(
                    Array.Empty <IActionDescriptorProvider>(),
                    Array.Empty <IActionDescriptorChangeProvider>());
            }

            var services = new ServiceCollection();

            services.AddSingleton(actionDescriptorCollectionProvider);

            var dataSource = new MvcEndpointDataSource(
                actionDescriptorCollectionProvider,
                mvcEndpointInvokerFactory ?? new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty <IActionInvokerProvider>())));

            return(dataSource);
        }
Esempio n. 6
0
        public MvcEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            MvcEndpointInvokerFactory invokerFactory,
            IEnumerable <IActionDescriptorChangeProvider> actionDescriptorChangeProviders,
            IServiceProvider serviceProvider)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            if (actionDescriptorChangeProviders == null)
            {
                throw new ArgumentNullException(nameof(actionDescriptorChangeProviders));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            _actions        = actions;
            _invokerFactory = invokerFactory;
            _actionDescriptorChangeProviders = actionDescriptorChangeProviders.ToArray();
            _httpContextInstance             = new DefaultHttpContext()
            {
                RequestServices = serviceProvider
            };

            ConventionalEndpointInfos = new List <MvcEndpointInfo>();

            Extensions.Primitives.ChangeToken.OnChange(
                GetCompositeChangeToken,
                UpdateEndpoints);
        }
Esempio n. 7
0
        private MvcEndpointDataSource CreateMvcEndpointDataSource(
            IActionDescriptorCollectionProvider actionDescriptorCollectionProvider = null,
            MvcEndpointInvokerFactory mvcEndpointInvokerFactory = null)
        {
            if (actionDescriptorCollectionProvider == null)
            {
                actionDescriptorCollectionProvider = new DefaultActionDescriptorCollectionProvider(
                    Array.Empty <IActionDescriptorProvider>(),
                    Array.Empty <IActionDescriptorChangeProvider>());
            }

            var serviceProviderMock = new Mock <IServiceProvider>();

            serviceProviderMock.Setup(m => m.GetService(typeof(IActionDescriptorCollectionProvider))).Returns(actionDescriptorCollectionProvider);

            var dataSource = new MvcEndpointDataSource(
                actionDescriptorCollectionProvider,
                mvcEndpointInvokerFactory ?? new MvcEndpointInvokerFactory(new ActionInvokerFactory(Array.Empty <IActionInvokerProvider>())),
                serviceProviderMock.Object);

            return(dataSource);
        }
Esempio n. 8
0
        public MvcEndpointDataSource(
            IActionDescriptorCollectionProvider actions,
            MvcEndpointInvokerFactory invokerFactory,
            ParameterPolicyFactory parameterPolicyFactory)
        {
            if (actions == null)
            {
                throw new ArgumentNullException(nameof(actions));
            }

            if (invokerFactory == null)
            {
                throw new ArgumentNullException(nameof(invokerFactory));
            }

            if (parameterPolicyFactory == null)
            {
                throw new ArgumentNullException(nameof(parameterPolicyFactory));
            }

            _actions                = actions;
            _invokerFactory         = invokerFactory;
            _parameterPolicyFactory = parameterPolicyFactory;

            ConventionalEndpointInfos           = new List <MvcEndpointInfo>();
            AttributeRoutingConventionResolvers = new List <Func <ActionDescriptor, DefaultEndpointConventionBuilder> >();

            // IMPORTANT: this needs to be the last thing we do in the constructor. Change notifications can happen immediately!
            //
            // It's possible for someone to override the collection provider without providing
            // change notifications. If that's the case we won't process changes.
            if (actions is ActionDescriptorCollectionProvider collectionProviderWithChangeToken)
            {
                ChangeToken.OnChange(
                    () => collectionProviderWithChangeToken.GetChangeToken(),
                    UpdateEndpoints);
            }
        }