Skip to content

Instantly share code, notes, and snippets.

@sdanna
Created May 23, 2015 18:03
Show Gist options
  • Save sdanna/c48979cd941699da88c7 to your computer and use it in GitHub Desktop.
Save sdanna/c48979cd941699da88c7 to your computer and use it in GitHub Desktop.
I got the func
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