public ModuleActionInvokerProvider(
     IModuleFactory moduleFactory,
     IEnumerable<IFilterProvider> filterProviders,
     IReadOnlyList<IInputFormatter> inputFormatters,
     IReadOnlyList<IOutputFormatter> outputFormatters,
     IReadOnlyList<IModelBinder> modelBinders,
     IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
     IReadOnlyList<IValueProviderFactory> valueProviderFactories,
     IActionBindingContextAccessor actionBindingContextAccessor,
     IOptions<MvcOptions> optionsAccessor,
     ILogger logger,
     DiagnosticSource diagnostic,
     IServiceProvider serviceProvider)
 {
     _moduleFactory = moduleFactory;
     _filterProviders = filterProviders.OrderBy(p => p.Order).ToList();
     _inputFormatters = inputFormatters;
     _outputFormatters = outputFormatters;
     _modelBinders = modelBinders;
     _modelValidatorProviders = modelValidatorProviders;
     _valueProviderFactories = valueProviderFactories;
     _actionBindingContextAccessor = actionBindingContextAccessor;
     _optionsAccessor = optionsAccessor;
     _logger = logger;
     _diagnostic = diagnostic;
     _serviceProvider = serviceProvider;
 }
        /// <summary>
        /// Initializes a new instance of <see cref="DefaultViewComponentInvoker"/>.
        /// </summary>
        /// <param name="viewComponentFactory">The <see cref="IViewComponentFactory"/>.</param>
        /// <param name="viewComponentInvokerCache">The <see cref="ViewComponentInvokerCache"/>.</param>
        /// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
        /// <param name="logger">The <see cref="ILogger"/>.</param>
        public DefaultViewComponentInvoker(
            IViewComponentFactory viewComponentFactory,
            ViewComponentInvokerCache viewComponentInvokerCache,
            DiagnosticSource diagnosticSource,
            ILogger logger)
        {
            if (viewComponentFactory == null)
            {
                throw new ArgumentNullException(nameof(viewComponentFactory));
            }

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

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

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

            _viewComponentFactory = viewComponentFactory;
            _viewComponentInvokerCache = viewComponentInvokerCache;
            _diagnosticSource = diagnosticSource;
            _logger = logger;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new <see cref="ViewExecutor"/>.
        /// </summary>
        /// <param name="viewOptions">The <see cref="IOptions{MvcViewOptions}"/>.</param>
        /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
        /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
        /// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
        public ViewExecutor(
            IOptions<MvcViewOptions> viewOptions,
            IHttpResponseStreamWriterFactory writerFactory,
            ICompositeViewEngine viewEngine,
            DiagnosticSource diagnosticSource)
        {
            if (viewOptions == null)
            {
                throw new ArgumentNullException(nameof(viewOptions));
            }

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

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

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

            ViewOptions = viewOptions.Value;
            WriterFactory = writerFactory;
            ViewEngine = viewEngine;
            DiagnosticSource = diagnosticSource;
        }
 public ModuleActionInvoker(
     ActionContext actionContext,
     IReadOnlyList<IFilterProvider> filterProviders,
     IModuleFactory moduleFactory,
     ModuleActionDescriptor descriptor,
     IReadOnlyList<IInputFormatter> inputFormatters,
     IReadOnlyList<IOutputFormatter> outputFormatters,
     IReadOnlyList<IModelBinder> modelBinders,
     IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
     IReadOnlyList<IValueProviderFactory> valueProviderFactories,
     IActionBindingContextAccessor actionBindingContextAccessor,
     ILogger logger,
     DiagnosticSource diagnostic,
     int maxModelValidationErrors)
     : base(
           actionContext,
           filterProviders,
           inputFormatters,
           outputFormatters,
           modelBinders,
           modelValidatorProviders,
           valueProviderFactories,
           actionBindingContextAccessor,
           logger,
           diagnostic,
           maxModelValidationErrors)
 {
     _descriptor = descriptor;
     _moduleFactory = moduleFactory;
 }
        public _DefaultViewComponentInvoker(
            ITypeActivatorCache typeActivatorCache,
            IViewComponentActivator viewComponentActivator,
            DiagnosticSource diagnosticSource,
            ILogger logger)
        {
            if (typeActivatorCache == null)
            {
                throw new ArgumentNullException(nameof(typeActivatorCache));
            }

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

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

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

            _typeActivatorCache = typeActivatorCache;
            _viewComponentActivator = viewComponentActivator;
            _diagnosticSource = diagnosticSource;
            _logger = logger;
        }
 public SimpleInjectorViewComponentInvoker(DiagnosticSource source, ILogger logger,
     IViewComponentActivator viewComponentActivator, Container container)
     : base(source, logger)
 {
     this.viewComponentActivator = viewComponentActivator;
     this.container = container;
 }
 public CommonExceptionHandlerMiddleware(
     RequestDelegate next,
     ILoggerFactory loggerFactory,
     DiagnosticSource diagnosticSource,
     IOptions<ExceptionHandlerOptions> options = null
     )
 {
     _next = next;
     if(options == null)
     {
         _options = new ExceptionHandlerOptions();
     }
     else
     {
         _options = options.Value;
     }
     
     _logger = loggerFactory.CreateLogger<CommonExceptionHandlerMiddleware>();
     if (_options.ExceptionHandler == null)
     {
         _options.ExceptionHandler = _next;
     }
     _clearCacheHeadersDelegate = ClearCacheHeaders;
     _diagnosticSource = diagnosticSource;
 }
Exemplo n.º 8
0
 public MvcRouteHandler(
     IActionInvokerFactory actionInvokerFactory,
     IActionSelector actionSelector,
     DiagnosticSource diagnosticSource,
     ILoggerFactory loggerFactory)
     : this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null)
 {
 }
Exemplo n.º 9
0
        public ViewComponentInvokerFactory(
            ITypeActivatorCache typeActivatorCache,
            IViewComponentActivator viewComponentActivator,
            DiagnosticSource diagnosticSource,
            ILoggerFactory loggerFactory)
        {
            _typeActivatorCache = typeActivatorCache;
            _viewComponentActivator = viewComponentActivator;
            _diagnosticSource = diagnosticSource;

            _logger = loggerFactory.CreateLogger<DefaultViewComponentInvoker>();
        }
        public RelationalCommandBuilder(
            [NotNull] ISensitiveDataLogger logger,
            [NotNull] DiagnosticSource diagnosticSource,
            [NotNull] IRelationalTypeMapper typeMapper)
        {
            Check.NotNull(logger, nameof(logger));
            Check.NotNull(diagnosticSource, nameof(diagnosticSource));
            Check.NotNull(typeMapper, nameof(typeMapper));

            _logger = logger;
            _diagnosticSource = diagnosticSource;
            _typeMapper = typeMapper;
        }
Exemplo n.º 11
0
        public ControllerActionInvoker(
            ActionContext actionContext,
            ControllerActionInvokerCache controllerActionInvokerCache,
            IControllerFactory controllerFactory,
            ControllerActionDescriptor descriptor,
            IReadOnlyList<IInputFormatter> inputFormatters,
            IControllerActionArgumentBinder argumentBinder,
            IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
            IReadOnlyList<IValueProviderFactory> valueProviderFactories,
            ILogger logger,
            DiagnosticSource diagnosticSource,
            int maxModelValidationErrors)
            : base(
                  actionContext,
                  controllerActionInvokerCache,
                  inputFormatters,
                  modelValidatorProviders,
                  valueProviderFactories,
                  logger,
                  diagnosticSource,
                  maxModelValidationErrors)
        {
            if (controllerFactory == null)
            {
                throw new ArgumentNullException(nameof(controllerFactory));
            }

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

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

            _controllerFactory = controllerFactory;
            _descriptor = descriptor;
            _argumentBinder = argumentBinder;

            if (descriptor.MethodInfo == null)
            {
                throw new ArgumentException(
                    Resources.FormatPropertyOfTypeCannotBeNull(
                        nameof(descriptor.MethodInfo),
                        typeof(ControllerActionDescriptor)),
                    nameof(descriptor));
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Creates a new <see cref="PartialViewResultExecutor"/>.
        /// </summary>
        /// <param name="viewOptions">The <see cref="IOptions{MvcViewOptions}"/>.</param>
        /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
        /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
        /// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        public PartialViewResultExecutor(
            IOptions<MvcViewOptions> viewOptions,
            IHttpResponseStreamWriterFactory writerFactory,
            ICompositeViewEngine viewEngine,
            DiagnosticSource diagnosticSource,
            ILoggerFactory loggerFactory)
            : base(viewOptions, writerFactory, viewEngine, diagnosticSource)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            Logger = loggerFactory.CreateLogger<PartialViewResultExecutor>();
        }
        public ApiExceptionResponseMiddleware(RequestDelegate next, bool showExceptionDetails, ILogger<ApiExceptionResponseMiddleware> logger,
            DiagnosticSource diagnosticSource)
        {
            if (next == null)
                throw new ArgumentNullException(nameof(next));
            if (logger == null)
                throw new ArgumentNullException(nameof(logger));
            if (diagnosticSource == null)
                throw new ArgumentNullException(nameof(diagnosticSource));

            _next = next;
            _showExceptionDetails = showExceptionDetails;
            _logger = logger;
            _diagnosticSource = diagnosticSource;
        }
Exemplo n.º 14
0
        public MvcRouteHandler(
            IActionInvokerFactory actionInvokerFactory,
            IActionSelector actionSelector,
            DiagnosticSource diagnosticSource,
            ILoggerFactory loggerFactory,
            IActionContextAccessor actionContextAccessor)
        {
            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = actionContextAccessor;

            _actionInvokerFactory = actionInvokerFactory;
            _actionSelector = actionSelector;
            _diagnosticSource = diagnosticSource;
            _logger = loggerFactory.CreateLogger<MvcRouteHandler>();
        }
 public ExceptionHandlerMiddleware(
     RequestDelegate next, 
     ILoggerFactory loggerFactory, 
     ExceptionHandlerOptions options,
     DiagnosticSource diagnosticSource)
 {
     _next = next;
     _options = options;
     _logger = loggerFactory.CreateLogger<ExceptionHandlerMiddleware>();
     if (_options.ExceptionHandler == null)
     {
         _options.ExceptionHandler = _next;
     }
     _clearCacheHeadersDelegate = ClearCacheHeaders;
     _diagnosticSource = diagnosticSource;
 }
Exemplo n.º 16
0
 public ControllerActionInvokerProvider(
     IControllerFactory controllerFactory,
     ControllerActionInvokerCache controllerActionInvokerCache,
     IControllerArgumentBinder argumentBinder,
     IOptions<MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticSource diagnosticSource)
 {
     _controllerFactory = controllerFactory;
     _controllerActionInvokerCache = controllerActionInvokerCache;
     _argumentBinder = argumentBinder;
     _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
     _maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors;
     _logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
     _diagnosticSource = diagnosticSource;
 }
 public ModelBindingActionInvokerFactory(
     IControllerFactory controllerFactory,
     ControllerActionInvokerCache controllerActionInvokerCache,
     IControllerArgumentBinder argumentBinder,
     IOptions<MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticSource diagnosticSource)
 {
     this.controllerFactory = controllerFactory;
     this.argumentBinder = argumentBinder;
     this.controllerActionInvokerCache = controllerActionInvokerCache;
     this.valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
     this.maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors;
     this.logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
     this.diagnosticSource = diagnosticSource;
 }
 public ModelBindingActionInvoker(
     ActionContext actionContext,
     ControllerActionInvokerCache controllerActionInvokerCache,
     IControllerFactory controllerFactory,
     ControllerActionDescriptor descriptor,
     IReadOnlyList<IInputFormatter> inputFormatters,
     IControllerActionArgumentBinder controllerActionArgumentBinder,
     IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
     IReadOnlyList<IValueProviderFactory> valueProviderFactories,
     ILogger logger,
     DiagnosticSource diagnosticSource,
     int maxModelValidationErrors)
         : base(actionContext, controllerActionInvokerCache, controllerFactory, descriptor, inputFormatters, controllerActionArgumentBinder, modelValidatorProviders, valueProviderFactories, logger, diagnosticSource, maxModelValidationErrors)
 {
     this.controllerActionDescriptor = descriptor;
 }
Exemplo n.º 19
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RazorPageActivator"/> class.
 /// </summary>
 public RazorPageActivator(
     IModelMetadataProvider metadataProvider,
     IUrlHelperFactory urlHelperFactory,
     IJsonHelper jsonHelper,
     DiagnosticSource diagnosticSource,
     HtmlEncoder htmlEncoder,
     IModelExpressionProvider modelExpressionProvider)
 {
     _activationInfo = new ConcurrentDictionary<Type, PageActivationInfo>();
     _metadataProvider = metadataProvider;
     _urlHelperAccessor = context => urlHelperFactory.GetUrlHelper(context);
     _jsonHelperAccessor = context => jsonHelper;
     _diagnosticSourceAccessor = context => diagnosticSource;
     _htmlEncoderAccessor = context => htmlEncoder;
     _modelExpressionProviderAccessor = context => modelExpressionProvider;
 }
Exemplo n.º 20
0
        /// <summary>
        /// Creates a new <see cref="ViewResultExecutor"/>.
        /// </summary>
        /// <param name="viewOptions">The <see cref="IOptions{MvcViewOptions}"/>.</param>
        /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
        /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
        /// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
        /// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
        /// <param name="loggerFactory">The <see cref="ILoggerFactory"/>.</param>
        /// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
        public ViewResultExecutor(
            IOptions<MvcViewOptions> viewOptions,
            IHttpResponseStreamWriterFactory writerFactory,
            ICompositeViewEngine viewEngine,
            ITempDataDictionaryFactory tempDataFactory,
            DiagnosticSource diagnosticSource,
            ILoggerFactory loggerFactory,
            IModelMetadataProvider modelMetadataProvider)
            : base(viewOptions, writerFactory, viewEngine, tempDataFactory, diagnosticSource, modelMetadataProvider)
        {
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            Logger = loggerFactory.CreateLogger<ViewResultExecutor>();
        }
Exemplo n.º 21
0
        /// <summary>
        /// Creates a new <see cref="ViewExecutor"/>.
        /// </summary>
        /// <param name="viewOptions">The <see cref="IOptions{MvcViewOptions}"/>.</param>
        /// <param name="writerFactory">The <see cref="IHttpResponseStreamWriterFactory"/>.</param>
        /// <param name="viewEngine">The <see cref="ICompositeViewEngine"/>.</param>
        /// <param name="tempDataFactory">The <see cref="ITempDataDictionaryFactory"/>.</param>
        /// <param name="diagnosticSource">The <see cref="DiagnosticSource"/>.</param>
        /// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider" />.</param>
        public ViewExecutor(
            IOptions<MvcViewOptions> viewOptions,
            IHttpResponseStreamWriterFactory writerFactory,
            ICompositeViewEngine viewEngine,
            ITempDataDictionaryFactory tempDataFactory,
            DiagnosticSource diagnosticSource,
            IModelMetadataProvider modelMetadataProvider)
        {
            if (viewOptions == null)
            {
                throw new ArgumentNullException(nameof(viewOptions));
            }

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

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

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

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

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

            ViewOptions = viewOptions.Value;
            WriterFactory = writerFactory;
            ViewEngine = viewEngine;
            TempDataFactory = tempDataFactory;
            DiagnosticSource = diagnosticSource;
            _modelMetadataProvider = modelMetadataProvider;
        }
 public ControllerActionInvokerProvider(
     IControllerFactory controllerFactory,
     IEnumerable<IFilterProvider> filterProviders,
     IControllerActionArgumentBinder argumentBinder,
     IOptions<MvcOptions> optionsAccessor,
     ILoggerFactory loggerFactory,
     DiagnosticSource diagnosticSource)
 {
     _controllerFactory = controllerFactory;
     _filterProviders = filterProviders.OrderBy(item => item.Order).ToArray();
     _argumentBinder = argumentBinder;
     _inputFormatters = optionsAccessor.Value.InputFormatters.ToArray();
     _modelBinders = optionsAccessor.Value.ModelBinders.ToArray();
     _modelValidatorProviders = optionsAccessor.Value.ModelValidatorProviders.ToArray();
     _valueProviderFactories = optionsAccessor.Value.ValueProviderFactories.ToArray();
     _maxModelValidationErrors = optionsAccessor.Value.MaxModelValidationErrors;
     _logger = loggerFactory.CreateLogger<ControllerActionInvoker>();
     _diagnosticSource = diagnosticSource;
 }
        public ModelBindingActionInvoker(
            ControllerActionInvokerCache cache,
            IControllerFactory controllerFactory,
            IControllerArgumentBinder controllerArgumentBinder,
            ILogger logger,
            DiagnosticSource diagnosticSource,
            ActionContext actionContext,
            IReadOnlyList<IValueProviderFactory> valueProviderFactories,
            int maxModelValidationErrors)
                : base(cache, controllerFactory, controllerArgumentBinder, logger, diagnosticSource, actionContext, valueProviderFactories, maxModelValidationErrors)
        {
            this.BoundActionArguments = new Dictionary<string, object>();

            this.controllerFactory = controllerFactory;
            this.controllerArgumentBinder = controllerArgumentBinder;

            this.controllerContext = new ControllerContext(actionContext);
            this.controllerContext.ModelState.MaxAllowedErrors = maxModelValidationErrors;
            this.controllerContext.ValueProviderFactories = new List<IValueProviderFactory>(valueProviderFactories);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DeveloperExceptionPageMiddleware"/> class
        /// </summary>
        /// <param name="next"></param>
        /// <param name="options"></param>
        public DeveloperExceptionPageMiddleware(
            RequestDelegate next,
            ErrorPageOptions options,
            ILoggerFactory loggerFactory,
            IApplicationEnvironment appEnvironment,
            DiagnosticSource diagnosticSource)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

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

            _next = next;
            _options = options;
            _logger = loggerFactory.CreateLogger<DeveloperExceptionPageMiddleware>();
            _fileProvider = options.FileProvider ?? new PhysicalFileProvider(appEnvironment.ApplicationBasePath);
            _diagnosticSource = diagnosticSource;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DeveloperExceptionPageMiddleware"/> class
        /// </summary>
        /// <param name="next"></param>
        /// <param name="options"></param>
        /// <param name="loggerFactory"></param>
        /// <param name="hostingEnvironment"></param>
        /// <param name="diagnosticSource"></param>
        public DeveloperExceptionPageMiddleware(
            RequestDelegate next,
            IOptions <DeveloperExceptionPageOptions> options,
            ILoggerFactory loggerFactory,
            IHostingEnvironment hostingEnvironment,
            System.Diagnostics.DiagnosticSource diagnosticSource)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

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

            _next                     = next;
            _options                  = options.Value;
            _logger                   = loggerFactory.CreateLogger <DeveloperExceptionPageMiddleware>();
            _fileProvider             = _options.FileProvider ?? hostingEnvironment.ContentRootFileProvider;
            _diagnosticSource         = diagnosticSource;
            _exceptionDetailsProvider = new ExceptionDetailsProvider(_fileProvider, _options.SourceCodeLineCount);
        }
 public TestControllerActionInvoker(
     ActionContext actionContext,
     IFilterProvider[] filterProvider,
     MockControllerFactory controllerFactory,
     ControllerActionDescriptor descriptor,
     IReadOnlyList<IInputFormatter> inputFormatters,
     IControllerActionArgumentBinder controllerActionArgumentBinder,
     IReadOnlyList<IModelBinder> modelBinders,
     IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
     IReadOnlyList<IValueProviderFactory> valueProviderFactories,
     ILogger logger,
     DiagnosticSource diagnosticSource,
     int maxAllowedErrorsInModelState)
     : base(
           actionContext,
           filterProvider,
           controllerFactory,
           descriptor,
           inputFormatters,
           controllerActionArgumentBinder,
           modelBinders,
           modelValidatorProviders,
           valueProviderFactories,
           logger,
           diagnosticSource,
           maxAllowedErrorsInModelState)
 {
     ControllerFactory = controllerFactory;
 }
Exemplo n.º 27
0
        private void EnsureServices(HttpContext context)
        {
            if (_actionContextAccessor == null)
            {
                _actionContextAccessor = context.RequestServices.GetRequiredService<IActionContextAccessor>();
            }

            if (_actionInvokerFactory == null)
            {
                _actionInvokerFactory = context.RequestServices.GetRequiredService<IActionInvokerFactory>();
            }

            if (_actionSelector == null)
            {
                _actionSelector = context.RequestServices.GetRequiredService<IActionSelector>();
            }

            if (_logger == null)
            {
                var factory = context.RequestServices.GetRequiredService<ILoggerFactory>();
                _logger = factory.CreateLogger<MvcRouteHandler>();
            }
            
            if (_diagnosticSource == null)
            {
                _diagnosticSource = context.RequestServices.GetRequiredService<DiagnosticSource>();
            }
        }
        private PartialViewResultExecutor GetViewExecutor(DiagnosticSource diagnosticSource = null)
        {
            if (diagnosticSource == null)
            {
                diagnosticSource = new DiagnosticListener("Test");
            }

            var viewEngine = new Mock<IViewEngine>(MockBehavior.Strict);
            viewEngine
                .Setup(e => e.FindPartialView(It.IsAny<ActionContext>(), It.IsAny<string>()))
                .Returns<ActionContext, string>((_, name) => ViewEngineResult.Found(name, Mock.Of<IView>()));

            var options = new TestOptionsManager<MvcViewOptions>();
            options.Value.ViewEngines.Add(viewEngine.Object);

            var viewExecutor = new PartialViewResultExecutor(
                options,
                new TestHttpResponseStreamWriterFactory(),
                new CompositeViewEngine(options),
                diagnosticSource,
                NullLoggerFactory.Instance);

            return viewExecutor;
        }
 private IRelationalCommand CreateRelationalCommand(
     ISensitiveDataLogger logger = null,
     DiagnosticSource diagnosticSource = null,
     string commandText = "Command Text",
     IReadOnlyList<IRelationalParameter> parameters = null)
     => new RelationalCommand(
         logger ?? new FakeSensitiveDataLogger<RelationalCommand>(),
         diagnosticSource ?? new DiagnosticListener("Fake"),
         commandText,
         parameters ?? new IRelationalParameter[0]);
Exemplo n.º 30
0
        private void EnsureServices(HttpContext context)
        {
            if (_servicesRetrieved)
            {
                return;
            }

            var services = context.RequestServices;

            // Verify if AddMvc was done before calling UseMvc
            // We use the MvcMarkerService to make sure if all the services were added.
            MvcServicesHelper.ThrowIfMvcNotRegistered(services);

            // The IActionContextAccessor is optional. We want to avoid the overhead of using CallContext
            // if possible.
            _actionContextAccessor = services.GetService<IActionContextAccessor>();

            _actionInvokerFactory = services.GetRequiredService<IActionInvokerFactory>();
            _actionSelector = services.GetRequiredService<IActionSelector>();
            _diagnosticSource = services.GetRequiredService<DiagnosticSource>();

            var factory = services.GetRequiredService<ILoggerFactory>();
            _logger = factory.CreateLogger<MvcRouteHandler>();

            _servicesRetrieved = true;
        }
Exemplo n.º 31
0
        /// <summary>
        /// Locates and renders a view specified by <see cref="ViewName"/>. If <see cref="ViewName"/> is <c>null</c>,
        /// then the view name searched for is<c>&quot;Default&quot;</c>.
        /// </summary>
        /// <param name="context">The <see cref="ViewComponentContext"/> for the current component execution.</param>
        /// <returns>A <see cref="Task"/> which will complete when view rendering is completed.</returns>
        public async Task ExecuteAsync(ViewComponentContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            var viewEngine = ViewEngine ?? ResolveViewEngine(context);
            var viewData = ViewData ?? context.ViewData;
            var isNullOrEmptyViewName = string.IsNullOrEmpty(ViewName);

            string qualifiedViewName;
            if (!isNullOrEmptyViewName &&
                (ViewName[0] == '~' || ViewName[0] == '/'))
            {
                // View name that was passed in is already a rooted path, the view engine will handle this.
                qualifiedViewName = ViewName;
            }
            else
            {
                // This will produce a string like:
                //
                //  Components/Cart/Default
                //
                // The view engine will combine this with other path info to search paths like:
                //
                //  Views/Shared/Components/Cart/Default.cshtml
                //  Views/Home/Components/Cart/Default.cshtml
                //  Areas/Blog/Views/Shared/Components/Cart/Default.cshtml
                //
                // This supports a controller or area providing an override for component views.
                var viewName = isNullOrEmptyViewName ? DefaultViewName : ViewName;

                qualifiedViewName = string.Format(
                    CultureInfo.InvariantCulture,
                    ViewPathFormat,
                    context.ViewComponentDescriptor.ShortName,
                    viewName);
            }

            var view = FindView(context.ViewContext, viewEngine, qualifiedViewName);

            var childViewContext = new ViewContext(
                context.ViewContext,
                view,
                ViewData ?? context.ViewData,
                context.Writer);

            using (view as IDisposable)
            {
                if (_diagnosticSource == null)
                {
                    _diagnosticSource = context.ViewContext.HttpContext.RequestServices.GetRequiredService<DiagnosticSource>();
                }

                _diagnosticSource.ViewComponentBeforeViewExecute(context, view);

                await view.RenderAsync(childViewContext);

                _diagnosticSource.ViewComponentAfterViewExecute(context, view);
            }
        }