var reader = new ConfigurationReader();
var config = reader.Read("/A/B/C").As<CommonConfig>();
string someValue = config.SomeValue;
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
process.Start(); | |
ProcessKiller.KillWhenConsoleTerminates(process); | |
RunAndWait(process); |
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
public static class TestOutputHelper | |
{ | |
private static readonly AsyncLocal<ITestOutputHelper> CurrentTestOutputHelper | |
= new AsyncLocal<ITestOutputHelper>(); | |
public static void Capture(this ITestOutputHelper outputHelper) | |
{ | |
CurrentTestOutputHelper.Value = outputHelper; | |
} |
How often have you found yourself in a situation where you have some synchronous code where you would like to call an asynchronous method?
My guess is pretty often. Especially if you are working with legacy code and just starting to learn about async and await.
I am going to show you an example of such a situation and ways to deals with it.
Note: The sample code uses LightInject as the IoC container, but this example applies to all containers and even if you are doing "manual" dependency injection. Being the author of LightInject I felt it was a natural choice :)
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
# Injecting asynchronous services | |
How often have you found yourself in a situation where you have some synchronous code where you would like to call an asynchronous method? | |
My guess is pretty often. Especially if you are working with legacy code and just starting to learn about **async** and **await**. | |
I am going to show you an example of such a situation and ways to deals with it. | |
> Note: The sample code uses LightInject as the IoC container, but this example applies to all containers and even if you are doing "manual" dependency injection. Being the author of LightInject I felt it was a natural choice :) |
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
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Text.RegularExpressions; | |
using System.Xml; | |
using System.Xml.Linq; | |
namespace Formix.Utils | |
{ | |
class Program |
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
//Filter | |
git filter-branch --prune-empty --subdirectory-filter src/LightInject.AutoFactory master | |
//Push to new repo | |
git push [email protected]:seesharper/LightInject.Interception.git -f | |
//Add gitignore and attributes | |
//Pull new repo |
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
/// <summary> | |
/// A thread safe class that ensures that a given | |
/// <see cref="Action"/> is only executed once. | |
/// </summary> | |
public class RunOnce | |
{ | |
private Action action; | |
private bool hasExecuted; | |
private readonly object lockObject = new object(); |
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
/// <summary> | |
/// Extends the <see cref="Expression"/> class. | |
/// </summary> | |
public static class ExpressionExtensions | |
{ | |
/// <summary> | |
/// Flattens the <paramref name="expression"/> into an <see cref="IEnumerable{T}"/>. | |
/// </summary> | |
/// <param name="expression">The target <see cref="Expression"/>.</param> | |
/// <returns>The <see cref="Expression"/> represented as a list of sub expressions.</returns> |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reflection; | |
using LightInject; | |
namespace ConsoleApplication2 | |
{ | |
class Program | |
{ |