-
-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from stevejgordon/dev
Merging 2.0.0 codebase
- Loading branch information
Showing
25 changed files
with
534 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
39 changes: 39 additions & 0 deletions
39
samples/MvcCorrelationIdSample/Controllers/ValuesController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
samples/MvcCorrelationIdSample/MvcCorrelationIdSample.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
Oops, something went wrong.