Skip to content

Commit

Permalink
Merge pull request #7 from stevejgordon/dev
Browse files Browse the repository at this point in the history
Merging 2.0.0 codebase
  • Loading branch information
stevejgordon authored Dec 31, 2017
2 parents 3bcd32c + cca46d6 commit cf2214e
Show file tree
Hide file tree
Showing 25 changed files with 534 additions and 114 deletions.
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
language: csharp
dist: trusty
mono: none
dotnet: 2.0.0
install:
- dotnet restore
script:
- dotnet build
- dotnet test test/CorrelationId.Tests/CorrelationId.Tests.csproj
26 changes: 17 additions & 9 deletions CorrelationId.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26403.3
VisualStudioVersion = 15.0.27130.2003
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorrelationId", "src\CorrelationId\CorrelationId.csproj", "{865886FC-EBBE-49E1-8F49-FECD0408EF6E}"
EndProject
Expand All @@ -11,15 +11,20 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{EAF27B74-0
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{34C0F65A-8BF2-40DA-B0E7-844930EE2A7B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorrelationIdSample", "samples\CorrelationIdSample\CorrelationIdSample.csproj", "{3FC0B789-9079-4695-A574-61D96DB74A36}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CorrelationId.Tests", "test\CorrelationId.Tests\CorrelationId.Tests.csproj", "{41035337-9829-4A6A-8EA9-42CC94734CE6}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CorrelationId.Tests", "test\CorrelationId.Tests\CorrelationId.Tests.csproj", "{41035337-9829-4A6A-8EA9-42CC94734CE6}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{1DC2BB08-1FE8-43B1-BD2E-F55DA4B54038}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{5961B376-2D2A-441B-BF59-9A797AC9178B}"
ProjectSection(SolutionItems) = preProject
.travis.yml = .travis.yml
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MvcCorrelationIdSample", "samples\MvcCorrelationIdSample\MvcCorrelationIdSample.csproj", "{CDD51CCC-0764-4C8C-8EA2-2DAAAF4CE0F9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -30,21 +35,24 @@ Global
{865886FC-EBBE-49E1-8F49-FECD0408EF6E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{865886FC-EBBE-49E1-8F49-FECD0408EF6E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{865886FC-EBBE-49E1-8F49-FECD0408EF6E}.Release|Any CPU.Build.0 = Release|Any CPU
{3FC0B789-9079-4695-A574-61D96DB74A36}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{3FC0B789-9079-4695-A574-61D96DB74A36}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3FC0B789-9079-4695-A574-61D96DB74A36}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3FC0B789-9079-4695-A574-61D96DB74A36}.Release|Any CPU.Build.0 = Release|Any CPU
{41035337-9829-4A6A-8EA9-42CC94734CE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{41035337-9829-4A6A-8EA9-42CC94734CE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{41035337-9829-4A6A-8EA9-42CC94734CE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
{41035337-9829-4A6A-8EA9-42CC94734CE6}.Release|Any CPU.Build.0 = Release|Any CPU
{CDD51CCC-0764-4C8C-8EA2-2DAAAF4CE0F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CDD51CCC-0764-4C8C-8EA2-2DAAAF4CE0F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CDD51CCC-0764-4C8C-8EA2-2DAAAF4CE0F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CDD51CCC-0764-4C8C-8EA2-2DAAAF4CE0F9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{865886FC-EBBE-49E1-8F49-FECD0408EF6E} = {9A14C73A-D8FC-40C3-81FC-D0687F43FEAF}
{3FC0B789-9079-4695-A574-61D96DB74A36} = {34C0F65A-8BF2-40DA-B0E7-844930EE2A7B}
{41035337-9829-4A6A-8EA9-42CC94734CE6} = {EAF27B74-0B27-4BEE-9F82-DD5812B21B17}
{CDD51CCC-0764-4C8C-8EA2-2DAAAF4CE0F9} = {34C0F65A-8BF2-40DA-B0E7-844930EE2A7B}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {C0A37404-C50B-472E-9491-DDE2A4BDA882}
EndGlobalSection
EndGlobal
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![NuGet](https://img.shields.io/nuget/v/CorrelationId.svg)](https://www.nuget.org/packages/CorrelationId)
[![NuGet](https://img.shields.io/nuget/dt/CorrelationId.svg)](https://www.nuget.org/packages/CorrelationId)
[![Build Status](https://travis-ci.org/stevejgordon/CorrelationId.svg?branch=dev)](https://travis-ci.org/stevejgordon/CorrelationId)

This repo contains middleware for syncing a TraceIdentity (correlation ID) across ASP.NET Core APIs.

Expand Down
11 changes: 0 additions & 11 deletions build/dependencies.props

This file was deleted.

19 changes: 0 additions & 19 deletions samples/CorrelationIdSample/CorrelationIdSample.csproj

This file was deleted.

31 changes: 0 additions & 31 deletions samples/CorrelationIdSample/Startup.cs

This file was deleted.

39 changes: 39 additions & 0 deletions samples/MvcCorrelationIdSample/Controllers/ValuesController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using System.Collections.Generic;
using CorrelationId;
using Microsoft.AspNetCore.Mvc;

namespace MvcCorrelationIdSample.Controllers
{
[Route("api/[controller]")]
public class ValuesController : Controller
{
private readonly ScopedClass _scoped;
private readonly TransientClass _transient;
private readonly SingletonClass _singleton;
private readonly ICorrelationContextAccessor _correlationContext;

public ValuesController(ScopedClass scoped, TransientClass transient, SingletonClass singleton, ICorrelationContextAccessor correlationContext)

{
_scoped = scoped;
_transient = transient;
_singleton = singleton;
_correlationContext = correlationContext;
}

// GET api/values
[HttpGet]
public IEnumerable<string> Get()
{
var correlation = _correlationContext.CorrelationContext.CorrelationId;

return new []
{
$"DirectAccessor={correlation}",
$"Transient={_transient.GetCorrelationFromScoped}",
$"Scoped={_scoped.GetCorrelationFromScoped}",
$"Singleton={_singleton.GetCorrelationFromScoped}"
};
}
}
}
15 changes: 15 additions & 0 deletions samples/MvcCorrelationIdSample/MvcCorrelationIdSample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\CorrelationId\CorrelationId.csproj" />
</ItemGroup>

</Project>
18 changes: 18 additions & 0 deletions samples/MvcCorrelationIdSample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;

namespace MvcCorrelationIdSample
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:35192/",
"applicationUrl": "http://localhost:59922/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"StaticFileSample": {
"MvcCorrelationIdSample": {
"commandName": "Project",
"launchBrowser": true,
"launchUrl": "http://localhost:5000/",
"launchUrl": "api/values",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"applicationUrl": "http://localhost:59923/"
}
}
}
}
43 changes: 43 additions & 0 deletions samples/MvcCorrelationIdSample/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using CorrelationId;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace MvcCorrelationIdSample
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}

public IConfiguration Configuration { get; }

// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc();

services.AddCorrelationId();

services.AddScoped<ScopedClass>();
services.AddTransient<TransientClass>();
services.AddSingleton<SingletonClass>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.UseCorrelationId();

app.UseMvc();
}
}
}
40 changes: 40 additions & 0 deletions samples/MvcCorrelationIdSample/TestClasses.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using CorrelationId;

namespace MvcCorrelationIdSample
{
public class ScopedClass
{
private readonly ICorrelationContextAccessor _correlationContext;

public ScopedClass(ICorrelationContextAccessor correlationContext)
{
_correlationContext = correlationContext;
}

public string GetCorrelationFromScoped => _correlationContext.CorrelationContext.CorrelationId;
}

public class TransientClass
{
private readonly ICorrelationContextAccessor _correlationContext;

public TransientClass(ICorrelationContextAccessor correlationContext)
{
_correlationContext = correlationContext;
}

public string GetCorrelationFromScoped => _correlationContext.CorrelationContext.CorrelationId;
}

public class SingletonClass
{
private readonly ICorrelationContextAccessor _correlationContext;

public SingletonClass(ICorrelationContextAccessor correlationContext)
{
_correlationContext = correlationContext;
}

public string GetCorrelationFromScoped => _correlationContext.CorrelationContext.CorrelationId;
}
}
15 changes: 15 additions & 0 deletions samples/MvcCorrelationIdSample/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"Logging": {
"IncludeScopes": false,
"Debug": {
"LogLevel": {
"Default": "Warning"
}
},
"Console": {
"LogLevel": {
"Default": "Warning"
}
}
}
}
23 changes: 23 additions & 0 deletions src/CorrelationId/CorrelationContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;

namespace CorrelationId
{
/// <summary>
/// Provides access to per request correlation properties.
/// </summary>
public class CorrelationContext
{
internal CorrelationContext(string correlationId)
{
if (string.IsNullOrEmpty(correlationId))
throw new ArgumentNullException(nameof(correlationId));

CorrelationId = correlationId;
}

/// <summary>
/// The Correlation ID which is applicable to the current request.
/// </summary>
public string CorrelationId { get; }
}
}
16 changes: 16 additions & 0 deletions src/CorrelationId/CorrelationContextAccessor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Threading;

namespace CorrelationId
{
/// <inheritdoc />
public class CorrelationContextAccessor : ICorrelationContextAccessor
{
private static AsyncLocal<CorrelationContext> _correlationContext = new AsyncLocal<CorrelationContext>();

public CorrelationContext CorrelationContext
{
get => _correlationContext.Value;
set => _correlationContext.Value = value;
}
}
}
Loading

0 comments on commit cf2214e

Please sign in to comment.