开发者

How to add policy injection to a private method

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. Until now I have only added the attribute to public methods, in that case I added the attribute in the interface which is working correctly. Hope that anyone have a clue on how to make this work.

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 nam开发者_开发技巧e);
    void Delete(string name);
}


Got some help on this issue from Avanade support on CodePlex. They told me that you only could intercept public methods/properties. They also gave me the link to the limitations of the Enterprise Library Policy Injection Block, which can be found on MSDN at: http://msdn.microsoft.com/en-us/library/ff650508.aspx#intro_limitations

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜