Movig RequestServicesWebsite to BasicWebsite

This commit is contained in:
Kiran Challa 2015-11-24 10:27:43 -08:00
parent 362c81e9bb
commit 3c694ce77c
22 changed files with 31 additions and 135 deletions

13
Mvc.sln
View File

@ -84,8 +84,6 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "Microsoft.AspNet.Mvc.TagHel
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "PrecompilationWebSite", "test\WebSites\PrecompilationWebSite\PrecompilationWebSite.xproj", "{59E1BE90-92C1-4D35-ADCC-B69F49077C81}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "RequestServicesWebSite", "test\WebSites\RequestServicesWebSite\RequestServicesWebSite.xproj", "{F12E9CF0-4958-40C6-A6CD-759185157F84}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "RazorEmbeddedViewsWebSite", "test\WebSites\RazorEmbeddedViewsWebSite\RazorEmbeddedViewsWebSite.xproj", "{B18ADE62-35DE-4A06-8E1D-EDD6245F7F4D}"
EndProject
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "CompositeViewEngineWebSite", "test\WebSites\CompositeViewEngineWebSite\CompositeViewEngineWebSite.xproj", "{A853B2BA-4449-4908-A416-5A3C027FC22B}"
@ -528,16 +526,6 @@ Global
{59E1BE90-92C1-4D35-ADCC-B69F49077C81}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{59E1BE90-92C1-4D35-ADCC-B69F49077C81}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{59E1BE90-92C1-4D35-ADCC-B69F49077C81}.Release|x86.ActiveCfg = Release|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Debug|x86.ActiveCfg = Debug|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Release|Any CPU.Build.0 = Release|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{F12E9CF0-4958-40C6-A6CD-759185157F84}.Release|x86.ActiveCfg = Release|Any CPU
{B18ADE62-35DE-4A06-8E1D-EDD6245F7F4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B18ADE62-35DE-4A06-8E1D-EDD6245F7F4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B18ADE62-35DE-4A06-8E1D-EDD6245F7F4D}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
@ -1129,7 +1117,6 @@ Global
{B2347320-308E-4D2B-AEC8-005DFA68B0C9} = {32285FA4-6B46-4D6B-A840-2B13E4C8B58E}
{860119ED-3DB1-424D-8D0A-30132A8A7D96} = {3BA657BF-28B1-42DA-B5B0-1C4601FCF7B1}
{59E1BE90-92C1-4D35-ADCC-B69F49077C81} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{F12E9CF0-4958-40C6-A6CD-759185157F84} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{B18ADE62-35DE-4A06-8E1D-EDD6245F7F4D} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{A853B2BA-4449-4908-A416-5A3C027FC22B} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}
{14F79E79-AE79-48FA-95DE-D794EF4EABB3} = {16703B76-C9F7-4C75-AE6C-53D92E308E3C}

View File

@ -11,9 +11,9 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
{
// Each of these tests makes two requests, because we want each test to verify that the data is
// PER-REQUEST and does not linger around to impact the next request.
public class RequestServicesTest : IClassFixture<MvcTestFixture<RequestServicesWebSite.Startup>>
public class RequestServicesTest : IClassFixture<MvcTestFixture<BasicWebSite.Startup>>
{
public RequestServicesTest(MvcTestFixture<RequestServicesWebSite.Startup> fixture)
public RequestServicesTest(MvcTestFixture<BasicWebSite.Startup> fixture)
{
Client = fixture.Client;
}
@ -21,11 +21,10 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
public HttpClient Client { get; }
[Theory]
[InlineData("http://localhost/RequestScoped/FromController")]
[InlineData("http://localhost/Other/FromFilter")]
[InlineData("http://localhost/Other/FromView")]
[InlineData("http://localhost/Other/FromViewComponent")]
[InlineData("http://localhost/Other/FromActionArgument")]
[InlineData("http://localhost/RequestScopedService/FromFilter")]
[InlineData("http://localhost/RequestScopedService/FromView")]
[InlineData("http://localhost/RequestScopedService/FromViewComponent")]
[InlineData("http://localhost/RequestScopedService/FromActionArgument")]
public async Task RequestServices(string url)
{
for (var i = 0; i < 2; i++)
@ -49,7 +48,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
public async Task RequestServices_TagHelper()
{
// Arrange
var url = "http://localhost/Other/FromTagHelper";
var url = "http://localhost/RequestScopedService/FromTagHelper";
// Act & Assert
for (var i = 0; i < 2; i++)
@ -71,7 +70,7 @@ namespace Microsoft.AspNet.Mvc.FunctionalTests
public async Task RequestServices_ActionConstraint()
{
// Arrange
var url = "http://localhost/Other/FromActionConstraint";
var url = "http://localhost/RequestScopedService/FromActionConstraint";
// Act & Assert
var requestId1 = "b40f6ec1-8a6b-41c1-b3fe-928f581ebaf5";

View File

@ -50,7 +50,6 @@
"RazorEmbeddedViewsWebSite": "1.0.0",
"RazorPageExecutionInstrumentationWebSite": "1.0.0",
"RazorWebSite": "1.0.0",
"RequestServicesWebSite": "1.0.0",
"ResponseCacheWebSite": "1.0.0",
"RoutingWebSite": "1.0.0",
"TagHelperSample.Web": "1.0.0",

View File

@ -3,10 +3,10 @@
using Microsoft.AspNet.Mvc;
namespace RequestServicesWebSite
namespace BasicWebSite
{
[Route("Other/[action]")]
public class OtherController : Controller
[Route("RequestScopedService/[action]")]
public class RequestScopedServiceController : Controller
{
// This only matches a specific requestId value
[HttpGet]

View File

@ -3,11 +3,10 @@
using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.Extensions.DependencyInjection;
namespace RequestServicesWebSite
namespace BasicWebSite
{
// Initializes a scoped-service with a request Id from a header
public class RequestIdMiddleware
@ -19,7 +18,7 @@ namespace RequestServicesWebSite
_next = next;
}
public async Task Invoke(HttpContext context)
public Task Invoke(HttpContext context)
{
var requestIdService = context.RequestServices.GetService<RequestIdService>();
if (requestIdService.RequestId != null)
@ -30,7 +29,7 @@ namespace RequestServicesWebSite
var requestId = context.Request.Headers["RequestId"];
requestIdService.RequestId = requestId;
await _next(context);
return _next(context);
}
}
}

View File

@ -4,7 +4,7 @@
using System;
using Microsoft.AspNet.Http;
namespace RequestServicesWebSite
namespace BasicWebSite
{
public class RequestIdService
{

View File

@ -3,7 +3,7 @@
using Microsoft.AspNet.Mvc;
namespace RequestServicesWebSite
namespace BasicWebSite
{
public class RequestIdViewComponent : ViewComponent
{

View File

@ -3,11 +3,10 @@
using System;
using System.Collections.Concurrent;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.Extensions.DependencyInjection;
namespace RequestServicesWebSite
namespace BasicWebSite
{
// Only matches when the requestId is the same as the one passed in the constructor.
public class RequestScopedActionConstraintAttribute : Attribute, IActionConstraintFactory

View File

@ -5,7 +5,7 @@ using System;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Filters;
namespace RequestServicesWebSite
namespace BasicWebSite
{
public class RequestScopedFilter : IActionFilter
{

View File

@ -3,7 +3,7 @@
using Microsoft.AspNet.Razor.TagHelpers;
namespace RequestServicesWebSite
namespace BasicWebSite
{
public class RequestScopedTagHelper : TagHelper
{
@ -11,7 +11,7 @@ namespace RequestServicesWebSite
{
RequestIdService = service;
}
public RequestIdService RequestIdService { get; }
public override void Process(TagHelperContext context, TagHelperOutput output)

View File

@ -18,12 +18,17 @@ namespace BasicWebSite
});
services.AddLogging();
services.AddSingleton<IActionDescriptorProvider, ActionDescriptorCreationCounter>();
services.AddScoped<RequestIdService>();
}
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
// Initializes the RequestId service for each request
app.UseMiddleware<RequestIdMiddleware>();
// Add MVC to the request pipeline
app.UseMvc(routes =>
{

View File

@ -0,0 +1,3 @@
@using BasicWebSite
@addTagHelper BasicWebSite.RequestScopedTagHelper, BasicWebSite
<request-scoped></request-scoped>

View File

@ -0,0 +1,3 @@
@using BasicWebSite
@inject RequestIdService RequestIdService
@RequestIdService.RequestId

View File

@ -1,17 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc;
namespace RequestServicesWebSite
{
[Route("RequestScoped/[action]")]
public class RequestScopedServiceController
{
[HttpGet]
public string FromController([FromServices] RequestIdService requestIdService)
{
return requestIdService.RequestId;
}
}
}

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>f12e9cf0-4958-40c6-a6cd-759185157f84</ProjectGuid>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\..\..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<DevelopmentServerPort>40959</DevelopmentServerPort>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>

View File

@ -1,32 +0,0 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Internal;
using Microsoft.Extensions.DependencyInjection;
namespace RequestServicesWebSite
{
public class Startup
{
// Set up application services
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();
services.AddScoped<RequestIdService>();
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
}
public void Configure(IApplicationBuilder app)
{
app.UseCultureReplacer();
// Initializes the RequestId service for each request
app.UseMiddleware<RequestIdMiddleware>();
app.UseMvcWithDefaultRoute();
}
}
}

View File

@ -1,3 +0,0 @@
@using RequestServicesWebSite
@addTagHelper RequestServicesWebSite.RequestScopedTagHelper, RequestServicesWebSite
<request-scoped></request-scoped>

View File

@ -1,3 +0,0 @@
@using RequestServicesWebSite
@inject RequestIdService RequestIdService
@RequestIdService.RequestId

View File

@ -1,19 +0,0 @@
{
"webroot": "wwwroot",
"exclude": "wwwroot/**/*",
"commands": {
"web": "Microsoft.AspNet.Hosting server=Microsoft.AspNet.Server.WebListener server.urls=http://localhost:5001",
"kestrel": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.Kestrel --server.urls http://localhost:5000"
},
"dependencies": {
"Microsoft.AspNet.Server.Kestrel": "1.0.0-*",
"Microsoft.AspNet.Mvc": "6.0.0-*",
"Microsoft.AspNet.Mvc.TestConfiguration": "1.0.0",
"Microsoft.AspNet.Server.WebListener": "1.0.0-*",
"Microsoft.AspNet.StaticFiles": "1.0.0-*"
},
"frameworks": {
"dnx451": { },
"dnxcore50": { }
}
}

View File

@ -1,5 +0,0 @@
RequestServicesWebSite
===
This web site registers services which are scoped per request. This web site is used for functional testing
to ensure that the services are per-request and does not linger around to impact the next request.