Resolving Instances with Delegates in Unity
Asked Answered
C

1

6

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

Chemarin answered 13/6, 2012 at 21:44 Comment(0)
E
10

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.

Exquisite answered 14/6, 2012 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.