CONTEXT:
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):
Unity / EntLib: Injecting a dependency into a CustomTraceListener
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:
GetCreationExpression()
...method. In Ent Lib 6 the new functionality is provided in the:
CoreBuildTraceListener()
...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, Enterprise Library no longer uses the Unity container to resolve instances. The:
EnterpriseLibraryCoreExtension
...has been removed. The new approach would be something along the lines of:
container.RegisterInstance(logWriterFactory.Create());
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.
QUESTION(s):
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 (if possible, please could you provide a simple example?) or...
c. Has this functionality regressed?