Note that there are some explanatory texts on larger screens.

plurals
  1. POEnt Lib 6 / Unity 3: Injecting a dependency into a CustomTraceListener
    primarykey
    data
    text
    <p>CONTEXT:</p> <p>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.</p> <p>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):</p> <p><a href="https://stackoverflow.com/questions/3438362/unity-entlib-injecting-a-dependency-into-a-customtracelistener">Unity / EntLib: Injecting a dependency into a CustomTraceListener</a></p> <p>However, it seems as though it is not a straightforward migration in Enterprise Library 6, for the following reasons:</p> <p>The Ent Lib 6 TraceListenerData class no longer makes available an override against the:</p> <p><code>GetCreationExpression()</code></p> <p>...method. In Ent Lib 6 the new functionality is provided in the:</p> <p><code>CoreBuildTraceListener()</code></p> <p>...method. My understanding is that the Ent Lib 5 <code>GetCreationExpression()</code> allowed 'marker's' to be placed in the returned expression that could be substituted when the Unity Container was resolved. The new <code>CoreBuildTraceListener()</code> returns a new instance of the Trace Listener.</p> <p>Also, Enterprise Library no longer uses the Unity container to resolve instances. The:</p> <p><code>EnterpriseLibraryCoreExtension</code></p> <p>...has been removed. The new approach would be something along the lines of:</p> <p>container.RegisterInstance(logWriterFactory.Create());</p> <p>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.</p> <p>QUESTION(s):</p> <p>Using Enterprise Library 6 and Unity 3, is it possible to either:</p> <p>a. Get a hold of the Unity Container in the <code>CoreBuildTraceListener()</code> 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...</p> <p>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...</p> <p>c. Has this functionality regressed?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload