Sep 9, 2011 at 4:02 PM
Edited Sep 9, 2011 at 7:01 PM
I am developing a classic three-tier MVC3 web application and I want to add logging, authentication and validation logic to the calls to my business layer. I am trying out various options and the one that I think I will go with is Enterprise Library
Validation on method calls (I can't reproduce its features easily) and my own ICallHandler for logging and authentication (I know EntLib has that but it seemed more heavyweight than I wanted).
I have developed a small series of Unit Tests just to check that things are happening as I expect and they don't. Basically in a case where the validation passes my ICallHandler is called three times. In the case where the validation fails my ICallHanlder
is called only once (and obviously before the validation calls an exception).
Here is the code that sets up the resolver:
public static UnityContainer SetupResolverEnterpriseLibraryAndOwnHandler(ICallHandler myMethodHandler)
var container = new UnityContainer();
// register all your components with the container here
// e.g. container.RegisterType<ITestService, TestService>();
////Add link to Enterprise Library
////Now enable Interception
.AddCallHandler(typeof(ValidationCallHandler), new InjectionConstructor("", SpecificationSource.Attributes));
//Now register the types that need interception
container.RegisterType<ITestClass1, TestClass1>(new InjectionConstructor(1, "main"),
And here is my unit test that fails on the last assert saying 'Expected: 1 but was 3"
public void Test15TryCountMethodAndRangeValidatorToPass()
var countCallHandler = new CountCallHandler(1);
var container = SetupUnity.SetupResolverEnterpriseLibraryAndOwnHandler(countCallHandler);
var testClass1 = container.Resolve<ITestClass1>();
I wonder if you have any idea why this is happening.
One other points while I am at it: I am trying to control the order that the various interceptions are called in, but I'm not sure how to do that? What Order number does EntLib's ValidationCallHandler have?
Thanks in advance