This file contains hidden or 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
[Test] | |
public void Should_be_able_to_consume() | |
{ | |
var autoResetEvent = new AutoResetEvent(false); | |
using (var channel = connection.OpenChannel()) | |
{ | |
channel.Declare(queue); | |
var settings = new ConsumerSettings(queue) |
This file contains hidden or 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.Concurrent; | |
using System.Threading; | |
using System.Threading.Tasks; | |
using System.Threading.Tasks.Dataflow; | |
namespace TDFDemo | |
{ | |
class Program | |
{ |
This file contains hidden or 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
// The Web API pipeline writes traces at the beginning and end of an operation. | |
// The TraceRecord class includes a TimeStamp property, so you can use this information | |
// to see how long various operations take. | |
// Traces written at the start of an operation have the Kind property set to TraceKind.Begin, | |
// and traces at the end of an operation have Kind set to TraceKind.End. To get the total | |
// execution time, match Begin and End traces. The following code shows a trace writer | |
// that collects traces and matches them when GetPerformanceRecords is called. You could even | |
// write an API controller that returns the performance data from this trace writer. |
This file contains hidden or 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 interface IPeopleContext : IDisposable, IEntitiesContext { | |
IDbSet<Person> People { get; set; } | |
IDbSet<Book> Books { get; set; } | |
} | |
public interface IEntitiesContext : IDisposable { | |
DbEntityEntry<TEntity> Entry<TEntity>(TEntity entity) where TEntity : class; | |
IDbSet<TEntity> Set<TEntity>() where TEntity : class; |
This file contains hidden or 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
// reference: http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html | |
static class Program { | |
static void Main(string[] args) { | |
for (int i = 1; i <= 100; i++) { | |
bool canBeMultipliedByFive = i.CanBeMultipliedBy(5); | |
bool canBeMultipliedByThree = i.CanBeMultipliedBy(3); |
This file contains hidden or 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
private static void RegisterRepositories(ContainerBuilder builder) { | |
Type baseEntityType = typeof(BaseEntity); | |
Assembly assembly = baseEntityType.Assembly; | |
IEnumerable<Type> entityTypes = assembly.GetTypes().Where(x => x.IsSubclassOf(baseEntityType)); | |
foreach (Type type in entityTypes) { | |
builder.RegisterType(typeof(EntityRepository<>).MakeGenericType(type)).As(typeof(IEntityRepository<>).MakeGenericType(type)).InstancePerApiRequest(); | |
} | |
} |
This file contains hidden or 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> | |
/// Base generic HttpClient class for the more specified clients. | |
/// </summary> | |
/// <typeparam name="TResult">Type of the result type which is expected.</typeparam> | |
/// <typeparam name="TId">Type of the id parameter for this client.</typeparam> | |
public abstract class HttpApiClient<TResult, TId> where TResult : IDto { | |
// Thoughts: | |
// 1- _httpClient which is passed here is fully configured HttpClient. | |
// No further alteration is required for headers, etc. |
This file contains hidden or 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
ServerSettings = new MongoServerSettings { | |
Servers = new List<MongoServerAddress> { | |
new MongoServerAddress("unittest") | |
} | |
}; | |
Server = new MongoServer(ServerSettings); | |
DatabaseSettings = new MongoDatabaseSettings("databaseName", new MongoCredentials("", ""), GuidRepresentation.Standard, ReadPreference.Primary, WriteConcern.Acknowledged); | |
Database = new MongoDatabase(Server, DatabaseSettings); |
This file contains hidden or 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 class CorrelationHandler : DelegatingHandler { | |
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) { | |
var response = await base.SendAsync(request, cancellationToken); | |
response.Headers.Add("X-CorrelationId", request.GetCorrelationId().ToString()); | |
return response; | |
} | |
} |
This file contains hidden or 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
// Before | |
public async Task DoWork() { | |
await Task.Delay(2000).ConfigureAwait(false); | |
Console.Writeline("Foo..."); | |
} | |
// After | |
public async Task DoWork() { | |