Policy Injection and Unity Integration?

Aug 8, 2008 at 9:32 PM
Just checking: is the Policy Injection App Block integrated w/ Unity yet?  Or does the PI block require you to pass Concrete classes in order to use the block?

Thanks.
Aug 11, 2008 at 3:42 PM
Integration is in the works, and you can use policy injection with interfaces.

Fernando
Aug 11, 2008 at 5:23 PM
When you say "with interfaces", how are the interfaces resolved?  By passing in the Concrete type as well, correct?
Aug 11, 2008 at 5:43 PM
This is what I mean:

using Microsoft.Practices.EnterpriseLibrary.PolicyInjection;

using Microsoft.Practices.EnterpriseLibrary.PolicyInjection.CallHandlers;

using Microsoft.Practices.Unity;

 

namespace UnityPiabRepro

{

    class Program

    {

        static void Main(string[] args)

        {

            IUnityContainer container = new UnityContainer();

            container.RegisterType<IFoo, MyFoo>();

            container.Configure<InjectedMembers>()

                .ConfigureInjectionFor<MyFoo>(new InjectionConstructor(10));

 

 

            IFoo theFoo = PolicyInjection.Wrap<IFoo>(container.Resolve<IFoo>());

 

            int value = theFoo.GetValue();

        }

    }

 

    public interface IFoo

    {

        [AuthorizationCallHandler("foo")]

        int GetValue();

    }

 

    public class MyFoo : IFoo

    {

        int value;

 

        public MyFoo(int value)

        {

            this.value = value;

        }

 

        public int GetValue()

        {

            return value;

        }

    }

}

 

 

What do you mean by "passing a concrete type"?

 

Fernando

<!--EndFragment-->
Aug 13, 2008 at 8:05 PM
Thanks Fernando, that's great.  I didn't know that I could wrap the Policy Injection that way.  So effectively, we already have Unity Integration inside of Policy Injection.  I suppose what's coming out though is a more streamlined way to do what you've shown here?

By passing in concrete types, I meant not resolving with the container, but actually passing the Concrete class as a parameter to the wrap method.
Aug 13, 2008 at 10:04 PM
Keep in mind that this approach is useful only for "external clients"; dependencies resolved internally cannot benefit from PIAB. That's the kind of value proper integration would provide.

Regards,
Fernando