Unity如何解析Func <type,type =“”> </type,>

时间:2011-03-10 23:00:06

标签: c# unity-container

有人可以通过Unity 2.0帮助我解决以下问题吗?

var instance = 
      new Class1(new Func<int, ReadOnlyCollection<Entity1> >(
                   (e) => new Entity1().GetAll()
                )
      );

谢谢, Moiz

1 个答案:

答案 0 :(得分:2)

这是你的意思吗?:

IUnityContainer container = ...;

container.RegisterInstance<Func<int, ReadOnlyCollection<Entity1>>(e => new Entity1().GetAll()));
container.RegisterType<Class1>();

var instance = container.Resolve<Class1>();