Click here to Skip to main content
15,891,981 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
It may be that I am going about this in the wrong way. I have implemented Unity Interception to handle my Logging and Exceptions. It works great, no logging or Exception Handling code in my domain.

I want to use the same strategy for Authorization and Validation. However I always run into the same issue: All the examples want to throw execptions when the pre-processing fails. All I want is to not execute the method, or prohibit access. In the example below, I prevent the method from being executed, but I always get a NullReferenceException. I believe the reason is that the method never gets invoked, therefore it is null. I don't want to do a try/catch around the method, this defeates the purpose of the Exception Handling I have in place. Suggestions?



Example:

C#
internal class ValidationCallHandler : ICallHandler
 {
     public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
     {
  // Preprocessing
         if (IsValidated())
         {
             return getNext()(input, getNext);
         }
 
        return input.CreateExceptionMethodReturn(new ValidationException());
     }
 
    private Boolean IsValidated()
     {
         return false;
     }
 

    public int Order { get; set; }
 }
 
[TestMethod]
 public void Be_Able_To_Validate_Account_Code_Setup()
 {
     AccountCodeSetup accountCodeSetup = _accountCodeSetupService.GetByName("Primary");
 
 // SaveAccountCodeSetupChanges is intercepted by the ValidationCallHandler
      _accountCodeSetupService.SaveAccountCodeSetupChanges(accountCodeSetup);
 }


Any suggestions?
Posted
Updated 29-May-12 4:59am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900