Created
May 23, 2015 18:03
-
-
Save sdanna/c48979cd941699da88c7 to your computer and use it in GitHub Desktop.
I got the func
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.Linq.Expressions; | |
using System.Runtime.CompilerServices; | |
using System.Text; | |
using System.Threading.Tasks; | |
using StructureMap; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var container = new Container(); | |
container.Configure(x => | |
{ | |
Func<int,int> addFunc = (y) => y + 2; | |
x.For<Func<int, int>>().Use(addFunc); | |
}); | |
var foo = container.GetInstance<Foo>(); | |
var output = foo.DoSomething(2); // Should be 4 | |
Console.WriteLine(output); | |
Console.ReadLine(); | |
} | |
} | |
public class Foo | |
{ | |
private readonly Func<int, int> _addFunc; | |
public Foo(Func<int, int> addFunc) | |
{ | |
_addFunc = addFunc; | |
} | |
public int DoSomething(int input) | |
{ | |
return _addFunc(input); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment