Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving Instances with Delegates in Unity

Has Unity, since February of 2011, improved this delegate story to achieve parity with StructureMap?

like image 767
Brent Arias Avatar asked Jun 13 '12 21:06

Brent Arias


1 Answers

Yes. Actually, this shipped with Unity 1.0 as the injection factory extension, so the blog post is wrong about the capability not being there.

In Unity 2.0 the story got a lot easier. You can do:

container.RegisterType<IWhatever>(
    new InjectionFactory(container => whateverFunctionYouWant()));

This results in a transient registration; you can use whatever lifetime manager you want.

like image 141
Chris Tavares Avatar answered Oct 28 '22 17:10

Chris Tavares