Last active
August 29, 2015 14:28
-
-
Save MiyamotoAkira/e4688b5f77ebb33851d4 to your computer and use it in GitHub Desktop.
Use of lambda delegate as factory.
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; | |
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(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple case in which a new object of a type is injected into another class.