Resolving dependency depending on requesting type

Jan 19, 2009 at 9:09 PM

I'm trying to learn Unity and as an example I wanted to use it to inject log4net logger instances. If there is just a single ILog instance this is not very hard. But I want to use the hierarchical nature of log4net loggers. So I need to somehow create a new logger instance passing in the type of the class that required the logger dependency. I looked at the static factory sample but I don't think the requesting type is available when resolving the dependency.

Has anyone done anything similar, or is this simply not possible with Unity. 

Jan 20, 2009 at 2:16 AM
I haven't really used log4net, what's the constructor for logger instances that you want to use?  I'm not sure if this will work for you but here's what I can come up at this moment.  You can probably register your logger instances with names representing the classname which requires that specific instance.  And when resolving the logger instances, just pass the classname.GetType.ToString(). 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.