Skip to content

Instantly share code, notes, and snippets.

@MiyamotoAkira
Last active August 29, 2015 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MiyamotoAkira/e4688b5f77ebb33851d4 to your computer and use it in GitHub Desktop.
Save MiyamotoAkira/e4688b5f77ebb33851d4 to your computer and use it in GitHub Desktop.
Use of lambda delegate as factory.
using System;
namespace TestFactorySubstitute
{
public class MyClass
{
public int Execute (Func<string, MyDependency> mydependency, int value)
{
return mydependency(DateTime.Now.ToShortTimeString()).Call(value);
}
}
public class MyDependency
{
public MyDependency(string currentTime)
{
Console.WriteLine("Hey: " + currentTime);
}
public int Call(int value)
{
return value;
}
}
public static class Program
{
public static void Main()
{
var myClass = new MyClass();
Console.WriteLine(myClass.Execute(x =>new MyDependency(x), 5));
Console.ReadLine();
}
}
}
@MiyamotoAkira
Copy link
Author

Simple case in which a new object of a type is injected into another class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment