Skip to content

Instantly share code, notes, and snippets.

View DavidSSL's full-sized avatar
💭
Set the status

DavidSSL

💭
Set the status
View GitHub Profile
@DavidSSL
DavidSSL / IResult
Created April 18, 2013 10:32
Illustatres how SemanticComparison helps with keeping code clean
public interface IResult
{
void Execute();
}
public class ErrorResult : IResult
{
public void Execute()
{
// Does something
public static void Main()
{
// 1. Instantiate the IWindsor container object
var container = new WindsorContainer();
// 2. Register the services and the respective components that implement them
container.Register(Types
.FromAssemblyContaining<HttpFileDownloader>
.BasedOn<IHtmlTitleRetriever>());
);
// 3. "Resolve" the root service
@DavidSSL
DavidSSL / AutoReg
Created April 10, 2013 15:10
Auto registration in Castle Windsor
public static void Main()
{
// 1. Instantiate the IWindsor container object
var container = new WindsorContainer();
// 2. Register the services and the respective components that implement them
container.Register(
Component.For( typeof( IHtmlTitleRetriever ) ).ImplementedBy( typeof(HtmlTitleRetriever) ) ,
Component.For( typeof( IHtmlTitleRetriever ) ).ImplementedBy( typeof(AnotherHttpFileDownloader ) )
);
@DavidSSL
DavidSSL / WorkingGetAfterPostReturnsCorrectStatusCodeWithPostedEntry
Last active December 15, 2015 04:50
GetAfterPostReturnsCorrectStatusCodeWithPostedEntry working
[Fact]
public void GetAfterPostReturnsCorrectStatusCodeWithPostedEntry()
{
using (var client = MyHttpClientFactory.Create())
{
var json = new
{
time = DateTimeOffset.Now
,
distance = 8500
@DavidSSL
DavidSSL / ReadAsJsonAsync
Created March 20, 2013 12:31
ReadAsJsonAsync
public static Task<dynamic> ReadAsJsonAsync(this HttpContent content)
{
if (content == null)
throw new ArgumentNullException("content");
return content.ReadAsStringAsync().ContinueWith(t =>
JsonConvert.DeserializeObject(t.Result));
}
@DavidSSL
DavidSSL / GetAfterPostReturnsCorrectStatusCodeWithPostedEntry
Created March 20, 2013 12:24
GetAfterPostReturnsCorrectStatusCodeWithPostedEntry
[Fact]
public void GetAfterPostReturnsCorrectStatusCodeWithPostedEntry()
{
using (var client = MyHttpClientFactory.Create())
{
var json = new
{
time = DateTimeOffset.Now
,
distance = 8500
@DavidSSL
DavidSSL / Tightly coupled code
Created March 17, 2013 15:16
Tightly coupled code example
class Program
{
static void Main()
{
Person person = new Person();
string dateOfBirth = "10 May 1989";
Console.WriteLine(person.GetAge(dateOfBirth));
}
}
@DavidSSL
DavidSSL / PassingInterface
Created March 16, 2013 18:49
Passing interface
public void SomeMethod(ISomeInterface interface)
{
interface.DoSomething();
}
@DavidSSL
DavidSSL / PassingConcreteObj
Created March 16, 2013 18:44
Passing concrete object
public void SomeMethod(SomeObject obj)
{
obj.DoSomething();
}
@DavidSSL
DavidSSL / TryCatchThrow
Created September 21, 2012 20:11
Try catch with throw
try
{
//Code to perform some operation
}
catch
{
//Code to handle any exception that occurred in the try block
throw; // the throw keyword will pass or throw the exception to the calling method
}