Adding PolicyInjection Handler on private methods

Topics: Policy Injection Application Block
May 13, 2011 at 7:57 AM

I'am having the following situation.

We have a private method where I want to add policyinjection by using a handlerAttribute. This method is called by a few different public methods which are defined in my interface. I'am instantiating the repository in a factory, where i return the wrapped object. Until now i'am not able to get the policyinjection working on my private method. Am I wrapping the object in a wrong way? I also tried to create the wrapped object by directly instantiating an repository object. See my implementation below:

// My factory implementation
public static ICacheRepository Repository()
{
    return PolicyInjection.Create<CacheRepository, ICacheRepository>();
}

// My repository
public class CacheRepository : MarshalByRefObject, ICacheRepository
{
    public void Add(string name)
    {
        Check(name);
    }

    public void Update(string name)
    {
        Check(name);
    }

    public void Delete(string name)
    {
        Check(name);
    }

    [NotNull] // <= HandlerAttribute
    private bool Check(string name)
    {
        return true;
    }
}

// My CacheRepository interface.
public interface ICacheRepository
{
    void Add(string name);
    void Update(string name);
    void Delete(string name);
}

May 13, 2011 at 10:47 AM

Hi,

You cannot intercept a private method. This is one of the limitations of Policy Injection. For more details, you can refer to Limitations of the Policy Injection Application Block . Hope this helps :)

 

Noel Angelo Bolasoc
Global Technologies and Solutions
Avanade, Inc.
entlib.support@avanade.com

May 13, 2011 at 11:48 AM

Thank you very much for you're help. That's the answer I was looking for.