Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What you will need to do is take advantage of unity interception pipeline.</p> <p>Unity provides a built-in policy injection behavior to facilitate the implementation of aop. The policy injection behavior attaches or injects some functionality to specific methods by using call handlers and matching rules on a per-method basis.</p> <p>a. Start with a custom interface of a ICallhandler.</p> <pre><code>&gt;&gt; public interface ILogAttributeHandler : ICallHandler &gt;&gt; { &gt;&gt; } &gt;&gt; </code></pre> <p>b. Add you implementation for your handler. This is the advice you want to apply when your method is intercepted.</p> <pre><code>&gt;&gt; public class ActivityAttributeHandler : ILogAttributeHandler &gt;&gt; { &gt;&gt; public ActivityAttributeHandler(string activityType) &gt;&gt; { &gt;&gt; ActivityType = activityType; &gt;&gt; } &gt;&gt; private string ActivityType { get; set; } &gt;&gt; public int Order { get; set; } &gt;&gt; public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext) &gt;&gt; { &gt;&gt; //// Invoke the handler &gt;&gt; IMethodReturn output = getNext()(input, getNext); &gt;&gt; //// Perform post-processing task &gt;&gt; var agent = output.ReturnValue as Agent; &gt;&gt; if (agent != null) &gt;&gt; { &gt;&gt; //// do work here &gt;&gt; } &gt;&gt; return getNext()(input, getNext); &gt;&gt; } } </code></pre> <p>c. Create your custom attribute, this will used as a pointcut in the program.</p> <pre><code>&gt;&gt; [AttributeUsage(AttributeTargets.Method)] &gt;&gt; public class ActivityAttribute : HandlerAttribute &gt;&gt; { &gt;&gt; private readonly string _activityName; &gt;&gt; public ActivityAttribute(string activityName) &gt;&gt; { &gt;&gt; _activityName = activityName; &gt;&gt; } &gt;&gt; } &gt;&gt; public override ICallHandler CreateHandler(IUnityContainer container) &gt;&gt; { &gt;&gt; return null; &gt;&gt;} </code></pre> <p>d. Now all you have left is to configure the interception within your unity configuration and add the attribute to your service interface operation that you want to be intercepted.</p> <pre><code>&gt; container &gt; .RegisterType&lt;ILogAttributeHandler, LogAttributeHandler&gt;() &gt; .AddNewExtension&lt;Interception&gt;() &gt; .Configure&lt;Interception&gt;() &gt; .SetInterceptorFor&lt;ISecurityRepository&gt;("SecurityRepository", new &gt; InterfaceInterceptor()); </code></pre> <p>e. Apply attributes to your interface operations</p> <pre><code>&gt;&gt;public interface ISecurityRepository &gt;&gt; { &gt;&gt; [OperationContract(IsInitiating = true)] &gt;&gt; [Activity("Logon")] &gt;&gt; IList&lt;vNavigationTree&gt; GetNavigationTree(string ticket) &gt;&gt;} </code></pre>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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