I am currently exploring some performance issues in a large application setup with Unity. I suspect we are highlighting too many objects. Since Unity handles creating / distributing objects, is there an event or something that I could log when the object was resolved or created by Unity? I need a complete trace so that I better understand what is happening.
Thank!
I would not go for custom LifetimeManager. If you want to know when Unity creates a new object, you should get this information directly from the Unity assembly pipeline.
LifetimeManager
TecX codeplex , . TecX.Unity( ). TecX.Unity.Tests , .
. . , : http://tavaresstudios.com/Blog/post/Writing-Custom-Lifetime-Managers.aspx
UnityContainerExtension. , TypeMapping:
UnityContainerExtension
TypeMapping
protected override void Initialize() { Context.Strategies.Add(_builderStrategy, UnityBuildStage.TypeMapping); }
PreBuildUp BuilderStrategy , , PostBuildUp , .
PreBuildUp
BuilderStrategy
PostBuildUp
A quick and dirty solution is to add some registration code to its default constructor for objects that, in your opinion, are created several times and unload the stack trace. You can also set breakpoints in this code and check the stack during debugging.