public CustomUrlHelper(IScopedInstance<ActionContext> contextAccessor, IActionSelector actionSelector, IOptions<AppOptions> appOptions) : base(contextAccessor, actionSelector) { _appOptions = appOptions; _httpContext = contextAccessor.Value.HttpContext; }
/// <summary> /// Initializes a new instance of the <see cref="UrlHelper"/> class using the specified action context and /// action selector. /// </summary> /// <param name="contextAccessor">The <see cref="IScopedInstance{TContext}"/> to access the action context /// of the current request.</param> /// <param name="actionSelector">The <see cref="IActionSelector"/> to be used for verifying the correctness of /// supplied parameters for a route. /// </param> public UrlHelper(IScopedInstance<ActionContext> contextAccessor, IActionSelector actionSelector) { _httpContext = contextAccessor.Value.HttpContext; _router = contextAccessor.Value.RouteData.Routers[0]; _ambientValues = contextAccessor.Value.RouteData.Values; _actionSelector = actionSelector; }
private MvcRouteHandler CreateMvcRouteHandler( ActionDescriptor actionDescriptor = null, IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, object diagnosticListener = null) { var actionContextAccessor = new ActionContextAccessor(); if (actionDescriptor == null) { var mockAction = new Mock<ActionDescriptor>(); actionDescriptor = mockAction.Object; } if (actionSelector == null) { var mockActionSelector = new Mock<IActionSelector>(); mockActionSelector .Setup(a => a.SelectCandidates(It.IsAny<RouteContext>())) .Returns(new ActionDescriptor[] { actionDescriptor }); mockActionSelector .Setup(a => a.SelectBestCandidate(It.IsAny<RouteContext>(), It.IsAny<IReadOnlyList<ActionDescriptor>>())) .Returns(actionDescriptor); actionSelector = mockActionSelector.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore"); if (diagnosticListener != null) { diagnosticSource.SubscribeWithAdapter(diagnosticListener); } if (invokerFactory == null) { var mockInvoker = new Mock<IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock<IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } return new MvcRouteHandler( invokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor); }
public MvcRouteHandler( IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, DiagnosticSource diagnosticSource, ILoggerFactory loggerFactory) : this(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory, actionContextAccessor: null) { }
public ODataActionSelector(IODataRoutingConvention convention, IActionDescriptorsCollectionProvider actionDescriptorsCollectionProvider, IActionSelectorDecisionTreeProvider decisionTreeProvider, IEnumerable<IActionConstraintProvider> actionConstraintProviders, ILoggerFactory loggerFactory) { _selector = new DefaultActionSelector(actionDescriptorsCollectionProvider, decisionTreeProvider, actionConstraintProviders, loggerFactory); _convention = convention; }
public CustomUrlHelper( IActionContextAccessor contextAccessor, IActionSelector actionSelector, IOptions<AppOptions> appOptions) : base(contextAccessor, actionSelector) { _appOptions = appOptions; _httpContext = contextAccessor.ActionContext.HttpContext; }
public MonsterFactory(IWeaponFactory weaponFactory, ISpellFactory spellFactory, IItemFactory itemFactory, IMonsterDataRepository monsterDataRepository, IActionSelector actionSelector, IStatsGenerator statsGenerator, IDice dice) { this.weaponFactory = weaponFactory; this.spellFactory = spellFactory; this.itemFactory = itemFactory; _actionSelector = actionSelector; _statsGenerator = statsGenerator; _dice = dice; monsterArchetypes = monsterDataRepository.GetAllMonsterArchetypes().ToList(); monsterModifiers = monsterDataRepository.GetAllMonsterModifiers().ToList(); }
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 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 DeviserControllerFactory(ILogger <DeviserControllerFactory> logger, IActionInvoker actionInvoker, IActionDescriptorCollectionProvider actionDescriptorCollectionProvider, IActionSelector actionSelector, IScopeService scopeService, IHtmlHelper htmlHelper, IModuleRepository moduleRepository, IModuleRegistry moduleRegistry) { _logger = logger; _actionInvoker = actionInvoker; _actionDescriptorCollectionProvider = actionDescriptorCollectionProvider; //_actionConstraintCache = container.Resolve<ActionConstraintCache>(); _actionSelector = actionSelector; _htmlHelper = htmlHelper; _moduleRepository = moduleRepository; _moduleRegistry = moduleRegistry; _scopeService = scopeService; }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddMvc(option => { });//.SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddApiVersioning(options => { options.DefaultApiVersion = new ApiVersion(1, 0); options.ReportApiVersions = true; options.AssumeDefaultVersionWhenUnspecified = true; //配置从Http请求报头获取api版本 options.ApiVersionReader = new HeaderApiVersionReader("api-version"); }); services.AddSingleton <IPersonRepository, MemoryPersonRepository>(); MvcOptions mvcOptions = services.BuildServiceProvider().CreateScope().ServiceProvider.GetService <IOptionsMonitor <MvcOptions> >().CurrentValue; MvcCompatibilityOptions mvcCompatibilityOptions = services.BuildServiceProvider().CreateScope().ServiceProvider.GetService <IOptionsMonitor <MvcCompatibilityOptions> >().CurrentValue; IActionSelector actionSelector = services.BuildServiceProvider().CreateScope().ServiceProvider.GetService <IActionSelector>(); }
public AuditLogMiddleware( RequestDelegate next, IActionDescriptorCollectionProvider provider, IActionSelector selector, IServiceProvider serviceProvider, ILogger <AuditLogMiddleware> logger ) { this.next = next ?? throw new ArgumentNullException(nameof(next)); this.provider = provider ?? throw new ArgumentNullException(nameof(provider)); this.selector = selector ?? throw new ArgumentNullException(nameof(selector)); if (serviceProvider == null) { throw new ArgumentNullException(nameof(serviceProvider)); } this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.scope = serviceProvider.CreateScope(); this.session = this.scope.ServiceProvider.GetService <NHibernate.ISession>(); cts = new CancellationTokenSource(); ThreadPool.QueueUserWorkItem(StartSaveAuditLog, cts.Token, preferLocal: false); }
/// <summary> /// Initializes a new instance of the <see cref="StubMonoRailServices"/> class. /// </summary> /// <param name="urlBuilder">The URL builder.</param> /// <param name="filterFactory">The filter factory.</param> /// <param name="viewEngineManager">The view engine manager.</param> /// <param name="actionSelector">The action selector.</param> /// <param name="dynamicActionProviderFactory">The dynamic action provider factory.</param> public StubMonoRailServices(IUrlBuilder urlBuilder, IFilterFactory filterFactory, IViewEngineManager viewEngineManager, IActionSelector actionSelector, IDynamicActionProviderFactory dynamicActionProviderFactory) { this.UrlBuilder = urlBuilder; this.FilterFactory = filterFactory; this.ViewEngineManager = viewEngineManager; this.ActionSelector = actionSelector; this.DynamicActionProviderFactory = dynamicActionProviderFactory; controllerTree = new DefaultControllerTree(); ControllerFactory = new DefaultControllerFactory(controllerTree); StaticResourceRegistry = new DefaultStaticResourceRegistry(); ControllerContextFactory = new DefaultControllerContextFactory(); ControllerDescriptorProvider = new DefaultControllerDescriptorProvider( new DefaultHelperDescriptorProvider(), new DefaultFilterDescriptorProvider(), new DefaultLayoutDescriptorProvider(), new DefaultRescueDescriptorProvider(), new DefaultResourceDescriptorProvider(), new DefaultTransformFilterDescriptorProvider(), new DefaultReturnBinderDescriptorProvider(), new DefaultDynamicActionProviderDescriptorProvider()); ResourceFactory = new DefaultResourceFactory(); ScaffoldingSupport = new StubScaffoldingSupport(); CacheProvider = new StubCacheProvider(); HelperFactory = new DefaultHelperFactory(); ServiceInitializer = new DefaultServiceInitializer(); ExtensionManager = new ExtensionManager(this); ValidatorRegistry = new CachedValidationRegistry(); JSONSerializer = new NewtonsoftJSONSerializer(); DictionaryAdapterFactory = new DictionaryAdapterFactory(); ScriptBuilder = new DefaultScriptBuilder(); }
private void EnsureServices(HttpContext context) { if (_servicesRetrieved) { return; } var services = context.RequestServices; // 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; }
private RouteContext CreateRouteContext( ActionDescriptor actionDescriptor = null, IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions<MvcOptions> optionsAccessor = null, object notificationListener = null) { var mockContextAccessor = new Mock<IScopedInstance<ActionContext>>(); if (actionDescriptor == null) { var mockAction = new Mock<ActionDescriptor>(); actionDescriptor = mockAction.Object; } if (actionSelector == null) { var mockActionSelector = new Mock<IActionSelector>(); mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>())) .Returns(Task.FromResult(actionDescriptor)); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock<IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock<IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { optionsAccessor = new MockMvcOptionsAccessor(); } var notifier = new Notifier(new NotifierMethodAdapter()); if (notificationListener != null) { notifier.EnlistTarget(notificationListener); } var httpContext = new Mock<HttpContext>(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IScopedInstance<ActionContext>))) .Returns(mockContextAccessor.Object); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>))) .Returns(optionsAccessor); httpContext.Setup(h => h.RequestServices.GetService(typeof(INotifier))) .Returns(notifier); return new RouteContext(httpContext.Object); }
void Start() { this.scene_controller = Singleton <IActionSelector> .Instance; //scene_controller = SSDirector.getInstance().currentSceneController as IActionSelector; scene_controller.psy_Manager = this; }
public DeviserRouteHandler( IActionSelector actionSelector) { _actionSelector = actionSelector; }
private RouteContext CreateRouteContext( ActionDescriptor actionDescriptor = null, IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions <MvcOptions> optionsAccessor = null, object telemetryListener = null) { if (actionDescriptor == null) { var mockAction = new Mock <ActionDescriptor>(); actionDescriptor = mockAction.Object; } if (actionSelector == null) { var mockActionSelector = new Mock <IActionSelector>(); mockActionSelector.Setup(a => a.SelectAsync(It.IsAny <RouteContext>())) .Returns(Task.FromResult(actionDescriptor)); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock <IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock <IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny <ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { optionsAccessor = new TestOptionsManager <MvcOptions>(); } var telemetry = new TelemetryListener("Microsoft.AspNet"); if (telemetryListener != null) { telemetry.SubscribeWithAdapter(telemetryListener); } var httpContext = new Mock <HttpContext>(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor))) .Returns(new ActionContextAccessor()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions <MvcOptions>))) .Returns(optionsAccessor); httpContext.Setup(h => h.RequestServices.GetService(typeof(TelemetrySource))) .Returns(telemetry); return(new RouteContext(httpContext.Object)); }
private RouteContext CreateRouteContext( ActionDescriptor actionDescriptor = null, IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions <MvcOptions> optionsAccessor = null, object diagnosticListener = null) { if (actionDescriptor == null) { var mockAction = new Mock <ActionDescriptor>(); actionDescriptor = mockAction.Object; } if (actionSelector == null) { var mockActionSelector = new Mock <IActionSelector>(); mockActionSelector.Setup(a => a.Select(It.IsAny <RouteContext>())) .Returns(actionDescriptor); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock <IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock <IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny <ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { optionsAccessor = new TestOptionsManager <MvcOptions>(); } var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore"); if (diagnosticListener != null) { diagnosticSource.SubscribeWithAdapter(diagnosticListener); } var routingFeature = new RoutingFeature(); var httpContext = new Mock <HttpContext>(); httpContext .Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor))) .Returns(new ActionContextAccessor()); httpContext .Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext .Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext .Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext .Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext .Setup(h => h.RequestServices.GetService(typeof(IOptions <MvcOptions>))) .Returns(optionsAccessor); httpContext .Setup(h => h.RequestServices.GetService(typeof(DiagnosticSource))) .Returns(diagnosticSource); httpContext .Setup(h => h.Features[typeof(IRoutingFeature)]) .Returns(routingFeature); var routeContext = new RouteContext(httpContext.Object); routingFeature.RouteData = routeContext.RouteData; return(routeContext); }
private RouteContext CreateRouteContext( ActionDescriptor actionDescriptor = null, IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions <MvcOptions> optionsAccessor = null, object notificationListener = null) { var mockContextAccessor = new Mock <IScopedInstance <ActionContext> >(); if (actionDescriptor == null) { var mockAction = new Mock <ActionDescriptor>(); actionDescriptor = mockAction.Object; } if (actionSelector == null) { var mockActionSelector = new Mock <IActionSelector>(); mockActionSelector.Setup(a => a.SelectAsync(It.IsAny <RouteContext>())) .Returns(Task.FromResult(actionDescriptor)); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock <IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock <IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny <ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { optionsAccessor = new MockMvcOptionsAccessor(); } var notifier = new Notifier(new NotifierMethodAdapter()); if (notificationListener != null) { notifier.EnlistTarget(notificationListener); } var httpContext = new Mock <HttpContext>(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IScopedInstance <ActionContext>))) .Returns(mockContextAccessor.Object); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions <MvcOptions>))) .Returns(optionsAccessor); httpContext.Setup(h => h.RequestServices.GetService(typeof(INotifier))) .Returns(notifier); return(new RouteContext(httpContext.Object)); }
public IActionResult FromServicesAction([FromServices] IActionSelector actionSelector) { return(null); }
/// <summary> /// Initializes a new instance of the <see cref="UrlHelper"/> class using the specified action context and /// action selector. /// </summary> /// <param name="actionContextAccessor">The <see cref="IActionContextAccessor"/> to access the action context /// of the current request.</param> /// <param name="actionSelector">The <see cref="IActionSelector"/> to be used for verifying the correctness of /// supplied parameters for a route. /// </param> public UrlHelper(IActionContextAccessor actionContextAccessor, IActionSelector actionSelector) { _actionContextAccessor = actionContextAccessor; _actionSelector = actionSelector; }
/// <summary> /// Initializes a new instance of the <see cref="ODataEndpointRouteValueTransformer"/> class. /// </summary> /// <param name="actionSelector">The injected <see cref="IActionSelector"/>.</param> public ODataEndpointRouteValueTransformer(IActionSelector actionSelector) { _selector = actionSelector; }
/// <summary> /// Sets the engine context. Also initialize all required services by querying /// <see cref="IEngineContext.Services"/> /// </summary> /// <param name="engineContext">The engine context.</param> public virtual void SetEngineContext(IEngineContext engineContext) { this.engineContext = engineContext; helperFactory = engineContext.Services.HelperFactory; // should not be null serviceInitializer = engineContext.Services.ServiceInitializer; // should not be null filterFactory = engineContext.Services.FilterFactory; // should not be null viewEngineManager = engineContext.Services.ViewEngineManager; // should not be null actionSelector = engineContext.Services.ActionSelector; // should not be null scaffoldSupport = engineContext.Services.ScaffoldingSupport; // might be null dynamicActionProviderFactory = engineContext.Services.DynamicActionProviderFactory; // should not be null }
private RouteContext CreateRouteContext( IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions<MvcOptions> optionsAccessor = null) { var mockContextAccessor = new Mock<IScopedInstance<ActionContext>>(); if (actionSelector == null) { var mockAction = new Mock<ActionDescriptor>(); var mockActionSelector = new Mock<IActionSelector>(); mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>())) .Returns(Task.FromResult(mockAction.Object)); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock<IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock<IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { var options = new Mock<IOptions<MvcOptions>>(); options.SetupGet(o => o.Options) .Returns(new MvcOptions()); optionsAccessor = options.Object; } var httpContext = new Mock<HttpContext>(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IScopedInstance<ActionContext>))) .Returns(mockContextAccessor.Object); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>))) .Returns(optionsAccessor); return new RouteContext(httpContext.Object); }
public AppUrlHelper(IActionContextAccessor actionContextAccessor, IActionSelector actionSelector) : base(actionContextAccessor, actionSelector) { }
private RouteContext CreateRouteContext( ActionDescriptor actionDescriptor = null, IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions<MvcOptions> optionsAccessor = null, object telemetryListener = null) { if (actionDescriptor == null) { var mockAction = new Mock<ActionDescriptor>(); actionDescriptor = mockAction.Object; } if (actionSelector == null) { var mockActionSelector = new Mock<IActionSelector>(); mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>())) .Returns(Task.FromResult(actionDescriptor)); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock<IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock<IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { optionsAccessor = new TestOptionsManager<MvcOptions>(); } var telemetry = new TelemetryListener("Microsoft.AspNet"); if (telemetryListener != null) { telemetry.SubscribeWithAdapter(telemetryListener); } var httpContext = new Mock<HttpContext>(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor))) .Returns(new ActionContextAccessor()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>))) .Returns(optionsAccessor); httpContext.Setup(h => h.RequestServices.GetService(typeof(TelemetrySource))) .Returns(telemetry); return new RouteContext(httpContext.Object); }
/// <summary> /// Initializes a new instance of the <see cref="ODataActionSelector" /> class. /// </summary> /// <param name="innerSelector">The inner action selector.</param> public ODataActionSelector(IActionSelector innerSelector) { _innerSelector = innerSelector; }
private RouteContext CreateRouteContext( ActionDescriptor actionDescriptor = null, IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions<MvcOptions> optionsAccessor = null, object diagnosticListener = null) { if (actionDescriptor == null) { var mockAction = new Mock<ActionDescriptor>(); actionDescriptor = mockAction.Object; } if (actionSelector == null) { var mockActionSelector = new Mock<IActionSelector>(); mockActionSelector.Setup(a => a.Select(It.IsAny<RouteContext>())) .Returns(actionDescriptor); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock<IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock<IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { optionsAccessor = new TestOptionsManager<MvcOptions>(); } var diagnosticSource = new DiagnosticListener("Microsoft.AspNetCore"); if (diagnosticListener != null) { diagnosticSource.SubscribeWithAdapter(diagnosticListener); } var routingFeature = new RoutingFeature(); var httpContext = new Mock<HttpContext>(); httpContext .Setup(h => h.RequestServices.GetService(typeof(IActionContextAccessor))) .Returns(new ActionContextAccessor()); httpContext .Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext .Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext .Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext .Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext .Setup(h => h.RequestServices.GetService(typeof(IOptions<MvcOptions>))) .Returns(optionsAccessor); httpContext .Setup(h => h.RequestServices.GetService(typeof(DiagnosticSource))) .Returns(diagnosticSource); httpContext .Setup(h => h.Features[typeof(IRoutingFeature)]) .Returns(routingFeature); var routeContext = new RouteContext(httpContext.Object); routingFeature.RouteData = routeContext.RouteData; return routeContext; }
public ControllerRunner(IActionInvokerFactory invokerFactory, IActionSelector selector) { _invokerFactory = invokerFactory; _selector = selector; }
public void SetActionSelector(IActionSelector actionSelector) { _actionSelector = actionSelector; }
/// <summary> /// Initializes a new instance of the <see cref="UrlHelper"/> class using the specified action context and /// action selector. /// </summary> /// <param name="actionContextAccessor">The <see cref="IActionContextAccessor"/> to access the action context /// of the current request.</param> /// <param name="actionSelector">The <see cref="IActionSelector"/> to be used for verifying the correctness of /// supplied parameters for a route. /// </param> public UrlHelper(IActionContextAccessor actionContextAccessor, IActionSelector actionSelector) { _actionContextAccessor = actionContextAccessor; _actionSelector = actionSelector; }
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 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; }
private RouteContext CreateRouteContext( IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null, IOptions <MvcOptions> optionsAccessor = null) { var mockContextAccessor = new Mock <IContextAccessor <ActionContext> >(); mockContextAccessor.Setup(c => c.SetContextSource( It.IsAny <Func <ActionContext> >(), It.IsAny <Func <ActionContext, ActionContext> >())) .Returns(NullDisposable.Instance); if (actionSelector == null) { var mockAction = new Mock <ActionDescriptor>(); var mockActionSelector = new Mock <IActionSelector>(); mockActionSelector.Setup(a => a.SelectAsync(It.IsAny <RouteContext>())) .Returns(Task.FromResult(mockAction.Object)); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock <IActionInvoker>(); mockInvoker.Setup(i => i.InvokeAsync()) .Returns(Task.FromResult(true)); var mockInvokerFactory = new Mock <IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny <ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } if (optionsAccessor == null) { var mockOptionsAccessor = new Mock <IOptions <MvcOptions> >(); mockOptionsAccessor.SetupGet(o => o.Options) .Returns(new MvcOptions()); optionsAccessor = mockOptionsAccessor.Object; } var httpContext = new Mock <HttpContext>(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IContextAccessor <ActionContext>))) .Returns(mockContextAccessor.Object); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(MvcMarkerService))) .Returns(new MvcMarkerService()); httpContext.Setup(h => h.RequestServices.GetService(typeof(IOptions <MvcOptions>))) .Returns(optionsAccessor); return(new RouteContext(httpContext.Object)); }
public JsonApiRouteHandler( IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector) : this(actionInvokerFactory, actionSelector, actionContextAccessor : null) { }
public IActionResult FromServicesAction([FromServices] IActionSelector actionSelector) => null;
private RouteContext CreateRouteContext( IActionSelector actionSelector = null, IActionInvokerFactory invokerFactory = null, ILoggerFactory loggerFactory = null) { var mockContextAccessor = new Mock<IContextAccessor<ActionContext>>(); mockContextAccessor.Setup(c => c.SetContextSource( It.IsAny<Func<ActionContext>>(), It.IsAny<Func<ActionContext, ActionContext>>())) .Returns(NullDisposable.Instance); if (actionSelector == null) { var mockAction = new Mock<ActionDescriptor>(); var mockActionSelector = new Mock<IActionSelector>(); mockActionSelector.Setup(a => a.SelectAsync(It.IsAny<RouteContext>())) .Returns(Task.FromResult(mockAction.Object)); actionSelector = mockActionSelector.Object; } if (invokerFactory == null) { var mockInvoker = new Mock<IActionInvoker>(); mockInvoker.Setup(i => i.InvokeActionAsync()) .Returns(Task.FromResult<object>(null)); var mockInvokerFactory = new Mock<IActionInvokerFactory>(); mockInvokerFactory.Setup(f => f.CreateInvoker(It.IsAny<ActionContext>())) .Returns(mockInvoker.Object); invokerFactory = mockInvokerFactory.Object; } if (loggerFactory == null) { loggerFactory = NullLoggerFactory.Instance; } var httpContext = new Mock<HttpContext>(); httpContext.Setup(h => h.RequestServices.GetService(typeof(IContextAccessor<ActionContext>))) .Returns(mockContextAccessor.Object); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionSelector))) .Returns(actionSelector); httpContext.Setup(h => h.RequestServices.GetService(typeof(IActionInvokerFactory))) .Returns(invokerFactory); httpContext.Setup(h => h.RequestServices.GetService(typeof(ILoggerFactory))) .Returns(loggerFactory); return new RouteContext(httpContext.Object); }
void Start() { scene_controller = Singleton <IActionSelector> .Instance; scene_controller.cc_Manager = this; }
public SubDomainRouteHandler(IActionInvokerFactory actionInvokerFactory, IActionSelector actionSelector, DiagnosticSource diagnosticSource, ILoggerFactory loggerFactory) : base(actionInvokerFactory, actionSelector, diagnosticSource, loggerFactory) { }