How to use SqlConfigurationSource with PIAB?

Topics: Policy Injection Application Block
Mar 11, 2009 at 6:05 PM
I am having trouble getting the SqlConfigurationSource to work with Policy Injection.  I am using Alois Kraus's patched version, and I can successfully work with the Data, Caching, and Exception Handling application blocks.  However, it won't work for me with the PIAB.  In particular, I want to use the Wrap() method of PolicyInjection, and I'm using attributes to decorate the methods that I want intercepted.  I see in v4.1 there is a new overload of Wrap which accepts a config source, however when I pass the sql source to that method it still blows up.  Here's a sample test for what I'm trying to do.  Basically, I want to be able to add exception handling via PolicyInjection.

using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;
using NUnit.Framework;
using SpecUnit;

namespace PolicyInjectionInTheDbTester
{
    [TestFixture]
    public class PolicyInjectionInTheDbTester : ITest
    {
        [Test]
        public void TestPI()
        {
            var sqlSource = ConfigUtils.GetSqlConfigSource();
            ITest tester = Microsoft.Practices.EnterpriseLibrary.PolicyInjection.PolicyInjection.Wrap<ITest>(sqlSource, this);
            int result = tester.GetValue();

            result.ShouldEqual(1);
        }

       
        public int GetValue()
        {
            return 1;
        }
    }

    public interface ITest
    {
        [ExceptionCallHandler(MyEntLib.ExceptionHandling.ExceptionPolicies.RichClientUI)]
        int GetValue();
    }
}

It's the call to Wrap() which blows.  This code works fine if I remove the attribute from the GetValue() method of ITest.  And of course, if I remove the SqlConfig from the picture, it all works, even with the attribute.  So it seems to me like the call to Wrap is attempting to evaluate the attributes on the ITest interface, and it's not using the supplied config source to lookup the settings.  Does this mean it's newing up a configuration source itself?  Shouldn't this be using the one I injected?

Can anyone offer some help with this?

Almost forgot:  There's a large stack trace with the error, but here's a portion of the message:  

 

Microsoft.Practices.Unity.ResolutionFailedException : Resolution of the dependency failed, type = "PolicyInjectionInTheDbTester.ITest", name = "". Exception message is: The current build operation (build key Build Key[PolicyInjectionInTheDbTester.ITest, null]) failed: The current build operation (build key Build Key[Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.ExceptionPolicyImpl, Rich Client UI Policy]) failed: Object reference not set to an instance of an object.

 

 

Mar 12, 2009 at 9:28 AM
Hi djensen,  I was able to repro your error.  Seems like a bug, but I can't be sure right now.  I tried removing the attribute and yes, I didn't encounter any error. But I also tried adding a namespace matching rule in order to intercept the same method and got the error so I believe it is trying to use the configuration source.  I'll do some more debugging and let you know what I can find out.


Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.
entlib.support@avanade.com