Note that there are some explanatory texts on larger screens.

plurals
  1. POUnobtrusive AOP with Spring.Net
    primarykey
    data
    text
    <p>I'm trying to add <strong>logging</strong> to <strong>methods decorated with an attribute</strong> using <strong>Spring.Net for AOP</strong>.</p> <p>Step 1: Reference 'Spring.Core', 'Spring.Aop', 'Common.Logging'</p> <p>Step 2: Create an advice:</p> <pre><code>using AopAlliance.Intercept; namespace MyApp.Aspects { public class LoggingAdvice : IMethodInterceptor { public object Invoke(IMethodInvocation invocation) { //todo: log started object rval = invocation.Proceed(); return rval; //todo: log finished } } } </code></pre> <p>Step 3: Create an attribute:</p> <pre><code>using System; namespace MyApp.Aspects { public class LoggingAttribute : Attribute { } } </code></pre> <p>Step 4: Edit web.config</p> <pre><code>&lt;configuration&gt; &lt;configSections&gt; &lt;sectionGroup name="spring"&gt; &lt;section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" /&gt; &lt;section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" /&gt; &lt;/sectionGroup&gt; &lt;/configSections&gt; &lt;spring&gt; &lt;context&gt; &lt;resource uri="config://spring/objects" /&gt; &lt;/context&gt; &lt;objects xmlns="http://www.springfrmework.net"&gt; &lt;object id="loggingAdvice" type="MyApp.Aspects.LoggingAdvice, MyApp"&gt;&lt;/object&gt; &lt;object id="loggingAdvisor" type="Spring.Aop.Support.DefaultPointcutAdvisor, Spring.Aop"&gt; &lt;property name="Advice" ref="loggingAdvice" /&gt; &lt;/object&gt; &lt;object type="Spring.Aop.Framework.AutoProxy.AttributeAutoProxyCreator, Spring.Aop"&gt; &lt;property name="AttributeTypes" value="MyApp.Aspects.LoggingAttribute"/&gt; &lt;property name="InterceptorNames" value="loggingAdvisor"/&gt; &lt;/object&gt; &lt;/objects&gt; &lt;/spring&gt; &lt;/configuration&gt; </code></pre> <p>Step 5: Decorate a method with the attribute:</p> <pre><code>using System.Web.Mvc; namespace MyApp.Controllers { public class MyController : Controller { [Logging] public ActionResult DoStuff() { //todo: implement } } } </code></pre> <p>The <strong>advice</strong> is <strong>never triggered</strong>. What am I missing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    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