Note that there are some explanatory texts on larger screens.

plurals
  1. POMicrosoft Unity - code to xml
    text
    copied!<p>Can someone provide the XML configuration I should use with Microsoft Unity application block in the Enterprise Library 4.1 to achieve the same result as the following?</p> <pre><code> using System; using Microsoft.Practices.Unity; using Microsoft.Practices.Unity.InterceptionExtension; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { IUnityContainer container = new UnityContainer(); container.AddNewExtension&lt;Interception&gt;(); container.RegisterType&lt;ILogger, Logger&gt;(); container.Configure&lt;Interception&gt;().SetInterceptorFor&lt;ILogger&gt;(new InterfaceInterceptor()); var logger = container.Resolve&lt;ILogger&gt;(); logger.Write("World."); Console.ReadKey(); } } public interface ILogger { [Test] void Write(string message); } public class Logger : ILogger { public void Write(string message) { Console.Write(message); } } public class TestAttribute : HandlerAttribute { public override ICallHandler CreateHandler(IUnityContainer container) { return new TestHandler(); } } public class TestHandler : ICallHandler { public int Order { get; set; } public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) { Console.Write("Hello, "); return getNext()(input, getNext); } } } </code></pre> <p>So instead of this:</p> <pre><code> IUnityContainer container = new UnityContainer(); container.AddNewExtension&lt;Interception&gt;(); container.RegisterType&lt;ILogger, Logger&gt;(); container.Configure&lt;Interception&gt;().SetInterceptorFor&lt;ILogger&gt;(new InterfaceInterceptor()); </code></pre> <p>I would have this:</p> <pre><code> IUnityContainer container = new UnityContainer(); UnityConfigurationSection section = (UnityConfigurationSection)ConfigurationManager.GetSection("unity"); section.Containers.Default.Configure(container); </code></pre> <p>with an XML config file.</p>
 

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