Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finished DomainEvents implementation.
Added ContextState helper.
- Loading branch information
Showing
5 changed files
with
158 additions
and
18 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,80 @@ | ||
namespace Hexa.Core | ||
{ | ||
using System.Collections.Generic; | ||
using System.Runtime.Remoting.Messaging; | ||
using System.ServiceModel; | ||
using System.Web; | ||
|
||
/// <summary> | ||
/// Context State Helper | ||
/// </summary> | ||
public static class ContextState | ||
{ | ||
/// <summary> | ||
/// Gets an item by the specified key. | ||
/// </summary> | ||
/// <typeparam name="T">Type of the item to get</typeparam> | ||
/// <param name="key">The key.</param> | ||
/// <returns> | ||
/// An item of type T | ||
/// </returns> | ||
public static T Get<T>(string key) | ||
{ | ||
if (OperationContext.Current != null) | ||
{ | ||
return (T)OperationContextState[key]; | ||
} | ||
else if (HttpContext.Current != null) | ||
{ | ||
return (T)HttpContext.Current.Items[key]; | ||
} | ||
else | ||
{ | ||
return (T)CallContext.GetData(key); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Stores the specified key. | ||
/// </summary> | ||
/// <param name="key">The key.</param> | ||
/// <param name="value">The value.</param> | ||
public static void Store(string key, object value) | ||
{ | ||
if (OperationContext.Current != null) | ||
{ | ||
OperationContextState[key] = value; | ||
} | ||
else if (HttpContext.Current != null) | ||
{ | ||
HttpContext.Current.Items[key] = value; | ||
} | ||
else | ||
{ | ||
CallContext.SetData(key, value); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Gets the state of the operation context. | ||
/// </summary> | ||
/// <value> | ||
/// The state of the operation context. | ||
/// </value> | ||
private static IDictionary<string, object> OperationContextState | ||
{ | ||
get | ||
{ | ||
OperationContextExtension extension = OperationContext.Current.Extensions.Find<OperationContextExtension>(); | ||
|
||
if (extension == null) | ||
{ | ||
extension = new OperationContextExtension(); | ||
OperationContext.Current.Extensions.Add(extension); | ||
} | ||
|
||
return extension.State; | ||
} | ||
} | ||
} | ||
} |
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 @@ | ||
namespace Hexa.Core | ||
{ | ||
using System.Collections.Generic; | ||
using System.ServiceModel; | ||
|
||
/// <summary> | ||
/// OperationContext Extension | ||
/// </summary> | ||
public class OperationContextExtension : IExtension<OperationContext> | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="OperationContextExtension"/> class. | ||
/// </summary> | ||
public OperationContextExtension() | ||
{ | ||
State = new Dictionary<string, object>(); | ||
} | ||
|
||
/// <summary> | ||
/// Gets the state. | ||
/// </summary> | ||
/// <value> | ||
/// The state. | ||
/// </value> | ||
public IDictionary<string, object> State { get; private set; } | ||
|
||
/// <summary> | ||
/// Attaches the specified owner. | ||
/// </summary> | ||
/// <param name="owner">The owner.</param> | ||
public void Attach(OperationContext owner) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Detaches the specified owner. | ||
/// </summary> | ||
/// <param name="owner">The owner.</param> | ||
public void Detach(OperationContext owner) | ||
{ | ||
} | ||
} | ||
} |
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
File renamed without changes.
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