-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
style: use file scoped namespaces, enable implicit usings and use spa…
…ces instead of tabs
- Loading branch information
Showing
63 changed files
with
3,502 additions
and
3,624 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
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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
namespace Correlate | ||
namespace Correlate; | ||
|
||
/// <summary> | ||
/// Represents the correlation context. | ||
/// </summary> | ||
public class CorrelationContext | ||
{ | ||
/// <summary> | ||
/// Represents the correlation context. | ||
/// </summary> | ||
public class CorrelationContext | ||
{ | ||
/// <summary> | ||
/// Gets or sets the correlation id. | ||
/// </summary> | ||
public string? CorrelationId { get; set; } | ||
} | ||
/// <summary> | ||
/// Gets or sets the correlation id. | ||
/// </summary> | ||
public string? CorrelationId { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,65 +1,60 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.Diagnostics; | ||
using System.Diagnostics.CodeAnalysis; | ||
|
||
namespace Correlate | ||
namespace Correlate; | ||
|
||
/// <summary> | ||
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled. | ||
/// </summary> | ||
public class ExceptionContext | ||
{ | ||
/// <summary> | ||
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled. | ||
/// </summary> | ||
public class ExceptionContext | ||
{ | ||
internal ExceptionContext(CorrelationContext correlationContext, Exception exception) | ||
{ | ||
CorrelationContext = correlationContext; | ||
Exception = exception; | ||
} | ||
internal ExceptionContext(CorrelationContext correlationContext, Exception exception) | ||
{ | ||
CorrelationContext = correlationContext; | ||
Exception = exception; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the correlation context | ||
/// </summary> | ||
public CorrelationContext CorrelationContext { get; } | ||
/// <summary> | ||
/// Gets the correlation context | ||
/// </summary> | ||
public CorrelationContext CorrelationContext { get; } | ||
|
||
/// <summary> | ||
/// Gets the exception that occurred. | ||
/// </summary> | ||
public Exception Exception { get; } | ||
/// <summary> | ||
/// Gets the exception that occurred. | ||
/// </summary> | ||
public Exception Exception { get; } | ||
|
||
/// <summary> | ||
/// Gets or sets whether the exception is considered handled. | ||
/// </summary> | ||
public bool IsExceptionHandled { get; set; } | ||
} | ||
/// <summary> | ||
/// Gets or sets whether the exception is considered handled. | ||
/// </summary> | ||
public bool IsExceptionHandled { get; set; } | ||
} | ||
|
||
/// <summary> | ||
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled and provide a return value. | ||
/// </summary> | ||
public class ExceptionContext<T> : ExceptionContext | ||
{ | ||
// ReSharper disable once RedundantDefaultMemberInitializer | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
private T _result = default!; | ||
/// <summary> | ||
/// Represents a context that provides access to the exception that occurred inside a correlated activity, with the ability to mark the exception as handled and provide a return value. | ||
/// </summary> | ||
public class ExceptionContext<T> : ExceptionContext | ||
{ | ||
// ReSharper disable once RedundantDefaultMemberInitializer | ||
[DebuggerBrowsable(DebuggerBrowsableState.Never)] | ||
private T _result = default!; | ||
|
||
internal ExceptionContext(CorrelationContext correlationContext, Exception exception) | ||
: base(correlationContext, exception) | ||
{ | ||
} | ||
internal ExceptionContext(CorrelationContext correlationContext, Exception exception) | ||
: base(correlationContext, exception) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Gets or sets the result value to return. | ||
/// </summary> | ||
[AllowNull] | ||
public T Result | ||
{ | ||
get | ||
{ | ||
return _result; | ||
} | ||
set | ||
{ | ||
IsExceptionHandled = true; | ||
_result = value!; | ||
} | ||
} | ||
} | ||
/// <summary> | ||
/// Gets or sets the result value to return. | ||
/// </summary> | ||
[AllowNull] | ||
public T Result | ||
{ | ||
get => _result; | ||
set | ||
{ | ||
IsExceptionHandled = true; | ||
_result = value!; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
namespace Correlate | ||
namespace Correlate; | ||
|
||
/// <summary> | ||
/// Describes an activity that can be started and stopped as desired to signal start/stop of a correlation context. | ||
/// </summary> | ||
public interface IActivity | ||
{ | ||
/// <summary> | ||
/// Describes an activity that can be started and stopped as desired to signal start/stop of a correlation context. | ||
/// </summary> | ||
public interface IActivity | ||
{ | ||
/// <summary> | ||
/// Signals the start of an the activity | ||
/// </summary> | ||
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> | ||
/// <returns>The created correlation context (also accessible via <see cref="ICorrelationContextAccessor"/>), or null if diagnostics and logging is disabled.</returns> | ||
CorrelationContext Start(string correlationId); | ||
/// <summary> | ||
/// Signals the start of an the activity | ||
/// </summary> | ||
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> | ||
/// <returns>The created correlation context (also accessible via <see cref="ICorrelationContextAccessor" />), or null if diagnostics and logging is disabled.</returns> | ||
CorrelationContext Start(string correlationId); | ||
|
||
/// <summary> | ||
/// Signals the activity is complete. | ||
/// </summary> | ||
void Stop(); | ||
} | ||
/// <summary> | ||
/// Signals the activity is complete. | ||
/// </summary> | ||
void Stop(); | ||
} |
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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
namespace Correlate | ||
namespace Correlate; | ||
|
||
/// <summary> | ||
/// Represents a factory that creates new activities, used to start a new correlation context. | ||
/// </summary> | ||
public interface IActivityFactory | ||
{ | ||
/// <summary> | ||
/// Represents a factory that creates new activities, used to start a new correlation context. | ||
/// </summary> | ||
public interface IActivityFactory | ||
{ | ||
/// <summary> | ||
/// Creates a new activity that can be started and stopped manually. | ||
/// </summary> | ||
/// <returns>The correlated activity.</returns> | ||
IActivity CreateActivity(); | ||
} | ||
} | ||
/// <summary> | ||
/// Creates a new activity that can be started and stopped manually. | ||
/// </summary> | ||
/// <returns>The correlated activity.</returns> | ||
IActivity CreateActivity(); | ||
} |
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 |
---|---|---|
@@ -1,36 +1,32 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
namespace Correlate; | ||
|
||
namespace Correlate | ||
/// <summary> | ||
/// Describes methods for starting a correlation context asynchronously. | ||
/// </summary> | ||
public interface IAsyncCorrelationManager | ||
{ | ||
/// <summary> | ||
/// Describes methods for starting a correlation context asynchronously. | ||
/// </summary> | ||
public interface IAsyncCorrelationManager | ||
{ | ||
/// <summary> | ||
/// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>. | ||
/// </summary> | ||
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> | ||
/// <param name="correlatedTask">The task to execute.</param> | ||
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param> | ||
/// <returns>An awaitable that completes once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns> | ||
/// <remarks> | ||
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. | ||
/// </remarks> | ||
Task CorrelateAsync(string? correlationId, Func<Task> correlatedTask, OnException? onException); | ||
/// <summary> | ||
/// Executes the <paramref name="correlatedTask" /> with its own <see cref="CorrelationContext" />. | ||
/// </summary> | ||
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> | ||
/// <param name="correlatedTask">The task to execute.</param> | ||
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param> | ||
/// <returns>An awaitable that completes once the <paramref name="correlatedTask" /> has executed and the correlation context has disposed.</returns> | ||
/// <remarks> | ||
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. | ||
/// </remarks> | ||
Task CorrelateAsync(string? correlationId, Func<Task> correlatedTask, OnException? onException); | ||
|
||
/// <summary> | ||
/// Executes the <paramref name="correlatedTask"/> with its own <see cref="CorrelationContext"/>. | ||
/// </summary> | ||
/// <typeparam name="T">The return type of the awaitable task.</typeparam> | ||
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> | ||
/// <param name="correlatedTask">The task to execute.</param> | ||
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param> | ||
/// <returns>An awaitable that completes with a result <typeparamref name="T"/> once the <paramref name="correlatedTask"/> has executed and the correlation context has disposed.</returns> | ||
/// <remarks> | ||
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. | ||
/// </remarks> | ||
Task<T> CorrelateAsync<T>(string? correlationId, Func<Task<T>> correlatedTask, OnException<T>? onException); | ||
} | ||
/// <summary> | ||
/// Executes the <paramref name="correlatedTask" /> with its own <see cref="CorrelationContext" />. | ||
/// </summary> | ||
/// <typeparam name="T">The return type of the awaitable task.</typeparam> | ||
/// <param name="correlationId">The correlation id to use, or null to generate a new one.</param> | ||
/// <param name="correlatedTask">The task to execute.</param> | ||
/// <param name="onException">A delegate to handle the exception inside the correlation scope, before it is disposed. Returns <see langword="true" /> to consider the exception handled, or <see langword="false" /> to throw.</param> | ||
/// <returns>An awaitable that completes with a result <typeparamref name="T" /> once the <paramref name="correlatedTask" /> has executed and the correlation context has disposed.</returns> | ||
/// <remarks> | ||
/// When logging and tracing are both disabled, no correlation context is created and the task simply executed as it normally would. | ||
/// </remarks> | ||
Task<T> CorrelateAsync<T>(string? correlationId, Func<Task<T>> correlatedTask, OnException<T>? onException); | ||
} |
21 changes: 10 additions & 11 deletions
21
src/Correlate.Abstractions/ICorrelationContextAccessor.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 |
---|---|---|
@@ -1,13 +1,12 @@ | ||
namespace Correlate | ||
namespace Correlate; | ||
|
||
/// <summary> | ||
/// Provides access to the <see cref="CorrelationContext" />. | ||
/// </summary> | ||
public interface ICorrelationContextAccessor | ||
{ | ||
/// <summary> | ||
/// Provides access to the <see cref="CorrelationContext"/>. | ||
/// </summary> | ||
public interface ICorrelationContextAccessor | ||
{ | ||
/// <summary> | ||
/// Gets or sets <see cref="CorrelationContext"/>. | ||
/// </summary> | ||
CorrelationContext? CorrelationContext { get; set; } | ||
} | ||
/// <summary> | ||
/// Gets or sets <see cref="CorrelationContext" />. | ||
/// </summary> | ||
CorrelationContext? CorrelationContext { get; set; } | ||
} |
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 |
---|---|---|
@@ -1,20 +1,19 @@ | ||
namespace Correlate | ||
namespace Correlate; | ||
|
||
/// <summary> | ||
/// Describes how to create/clean up a <see cref="CorrelationContext" />. | ||
/// </summary> | ||
public interface ICorrelationContextFactory | ||
{ | ||
/// <summary> | ||
/// Describes how to create/clean up a <see cref="CorrelationContext"/>. | ||
/// </summary> | ||
public interface ICorrelationContextFactory | ||
{ | ||
/// <summary> | ||
/// Creates a new <see cref="CorrelationContext"/>. | ||
/// </summary> | ||
/// <param name="correlationId">The correlation id to associate to the context.</param> | ||
/// <returns>The <see cref="CorrelationContext"/> containing the correlation id.</returns> | ||
CorrelationContext Create(string correlationId); | ||
/// <summary> | ||
/// Creates a new <see cref="CorrelationContext" />. | ||
/// </summary> | ||
/// <param name="correlationId">The correlation id to associate to the context.</param> | ||
/// <returns>The <see cref="CorrelationContext" /> containing the correlation id.</returns> | ||
CorrelationContext Create(string correlationId); | ||
|
||
/// <summary> | ||
/// Disposes the <see cref="CorrelationContext"/>. | ||
/// </summary> | ||
void Dispose(); | ||
} | ||
/// <summary> | ||
/// Disposes the <see cref="CorrelationContext" />. | ||
/// </summary> | ||
void Dispose(); | ||
} |
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 |
---|---|---|
@@ -1,14 +1,13 @@ | ||
namespace Correlate | ||
namespace Correlate; | ||
|
||
/// <summary> | ||
/// Describes a way of generating new correlation ids. | ||
/// </summary> | ||
public interface ICorrelationIdFactory | ||
{ | ||
/// <summary> | ||
/// Describes a way of generating new correlation ids. | ||
/// </summary> | ||
public interface ICorrelationIdFactory | ||
{ | ||
/// <summary> | ||
/// Creates a new correlation id. | ||
/// </summary> | ||
/// <returns>The new correlation id.</returns> | ||
string Create(); | ||
} | ||
/// <summary> | ||
/// Creates a new correlation id. | ||
/// </summary> | ||
/// <returns>The new correlation id.</returns> | ||
string Create(); | ||
} |
Oops, something went wrong.