I am using Enterprise Library 6 and Unity 3 throughout my solution to manage cross cutting concerns and as a lightweight container for managing Dependency Injection. I have a requirement to develop a Custom Trace Listener. I need to inject a dependency into
that Custom Trace Listener.
This functionality is available in Enterprise Library 5 and Unity 2. The following link provides a nice example of how it can be achieved (my own requirements are almost similar to those outlined in the link):
However, it seems as though it is not a straightforward migration in Enterprise Library 6, for the following reasons:
The Ent Lib 6 TraceListenerData class no longer makes available an override against the:
...method. In Ent Lib 6 the new functionality is provided in the:
...method. My understanding is that the Ent Lib 5 GetCreationExpression() allowed 'marker's' to be placed in the returned expression that could be substituted when the Unity Container was resolved. The new CoreBuildTraceListener() returns a new instance of
the Trace Listener.
Also, Ent Lib 6 no longer uses the Unity container to resolve instances. The:
...has been removed. The new approach would be something along the lines of:
However, for me this means that the CoreBuildTraceListener() is invoked (on logWriterFactory.Create()) before any call can be made to resolve a Interface through the Unity Container.
Using Enterprise Library 6 and Unity 3, is it possible to either:
a. Get a hold of the Unity Container in the CoreBuildTraceListener() method at the correct time - so I can find the appropriate Interface I need to inject into my Custom Trace Listener when the Custom Trace Listener is created or...
b. Is there a new approach to achieving the same end-goal that I don't know about that you could advise me on (if possible, please could you provide a simple example?) or...
c. Has this functionality regressed?
Thanks in advance.