如何向私有方法添加策略注入
我遇到以下情况。
我们有一个私有方法,我想通过使用 handlerAttribute 添加策略注入。该方法由我的接口中定义的几个不同的公共方法调用。我正在工厂中实例化存储库,并在其中返回包装的对象。到目前为止,我无法让策略注入在我的私有方法上工作。我是否以错误的方式包装了该对象?我还尝试通过直接实例化存储库对象来创建包装对象。到目前为止,我只将属性添加到公共方法中,在这种情况下,我在接口中添加了可以正常工作的属性。希望任何人都知道如何进行这项工作。
请参阅下面我的实现:
// 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);
}
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 name);
void Delete(string name);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从 CodePlex 上的埃维诺支持获得了有关此问题的一些帮助。他们告诉我你只能拦截公共方法/属性。他们还为我提供了企业库策略注入块限制的链接,可以在 MSDN 上找到该链接:http://msdn.microsoft.com/en-us/library/ff650508.aspx#intro_limitations
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