Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Define Prototype Interceptors with DefaultAdvisorAutoProxyCreator in Spring.NET
    primarykey
    data
    text
    <p>I am new to Spring.NET and am just playing around trying different things out. As part of my testing, I created a simple object:</p> <pre class="lang-cs prettyprint-override"><code>public interface ICommand { void Execute(object context); } </code></pre> <p>with one implementation:</p> <pre class="lang-cs prettyprint-override"><code>public class ServiceCommand : ICommand { public ServiceCommand() { Console.WriteLine("########## {0} ##########", GetType().Name); } public void Execute(object context) { Console.WriteLine("Service implementation: {0}.{1}", GetType().Name, MethodBase.GetCurrentMethod().Name); } } </code></pre> <p>Finally, I've a simple before advice as follows:</p> <pre class="lang-cs prettyprint-override"><code>public class ConsoleLoggingBeforeAdvice : IMethodBeforeAdvice { public ConsoleLoggingBeforeAdvice() { Console.WriteLine("########## {0} ##########", GetType().Name); } public void Before(MethodInfo method, object[] args, object target) { Console.WriteLine("Intercepted call to this method: {0}", method.Name); Console.WriteLine(" The target is : {0}", target); Console.WriteLine(" The arguments are : "); if (args != null) { foreach (object arg in args) { Console.WriteLine("\t: {0}", arg); } } } } </code></pre> <p>As you can see, much of this stuff is from the Spring.NET quick start samples. </p> <p>So, I configured the ServiceCommand to be wrapped in a ConsoleLoggingBeforeAdvice via ProxyFactoryObject and marked both the objects as prototype (see config below). This works as expected: each time we request a ServiceCommand, a new instance of both the object and associated interceptor is created:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;objects xmlns="http://www.springframework.net"&gt; &lt;object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false"&gt; &lt;property name="Advice"&gt; &lt;object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/&gt; &lt;/property&gt; &lt;/object&gt; &lt;object id="ServiceCommandTarget" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/&gt; &lt;object id="ServiceCommand" type ="Spring.Aop.Framework.ProxyFactoryObject"&gt; &lt;property name="IsSingleton" value="false"/&gt; &lt;property name="TargetName" value="ServiceCommandTarget"/&gt; &lt;property name="InterceptorNames"&gt; &lt;list&gt; &lt;value&gt;ConsoleLoggingBeforeAdvice&lt;/value&gt; &lt;/list&gt; &lt;/property&gt; &lt;/object&gt; &lt;/objects&gt; </code></pre> <p>However, when I try to achieve the same results via DefaultAdvisorAutoProxyCreator, everything works except that the interceptor is always created as Singleton (even though it's configured as singleton="false"). The config is as follows:</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;objects xmlns="http://www.springframework.net"&gt; &lt;object id="ConsoleLoggingBeforeAdvice" type="Spring.Aop.Support.DefaultPointcutAdvisor" singleton="false"&gt; &lt;property name="Advice"&gt; &lt;object type="Spring.Examples.AopQuickStart.ConsoleLoggingBeforeAdvice"/&gt; &lt;/property&gt; &lt;/object&gt; &lt;object id="ServiceCommand" type="Spring.Examples.AopQuickStart.ServiceCommand" singleton="false"/&gt; &lt;object type="Spring.Aop.Framework.AutoProxy.DefaultAdvisorAutoProxyCreator"/&gt; &lt;/objects&gt; </code></pre> <p>Now, how can I ensure that both the object and associated interceptor are treated as prototypes by DefaultAdvisorAutoProxyCreator?</p>
    singulars
    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