通过 DI 配置 Envers RevisionListener
为了向我们的应用程序添加审计跟踪,我们决定使用 NHibernate.Envers。为了允许特定于应用程序的修订跟踪,使用特定于用户的数据扩展了 DefaultRevisionEntity
。
public virtual void NewRevision( object revisionEntity )
{
var revisionData = revisionEntity as Revision;
if( revisionData != null )
{
// Set additional audit data.
var identity = UserAccessor.CurrentIdentity;
revisionData.UserId = identity.UserId;
revisionData.EmployeeId = identity.EmployeeId;
revisionData.UserName = identity.Name;
}
}
Envers 根据您的类所装饰的 RevisionEntity
属性来决定使用哪个 RevisionListener
:
[RevisionEntity( typeof( RevisionListener ) )]
我正在使用 ServiceLocator 模式将我的访问器注入到 RevisionListener
中>。目前,这是我必须使用 ServiceLocator 并且真的想摆脱它的唯一地方。
是否有另一种灵活的方法将我的 UserAccessor 注入到 RevisionEntity 中?
To add an audit trail to our application we decided to use NHibernate.Envers. To allow app specific tracking of revisions, the DefaultRevisionEntity
was extended with user specific data.
public virtual void NewRevision( object revisionEntity )
{
var revisionData = revisionEntity as Revision;
if( revisionData != null )
{
// Set additional audit data.
var identity = UserAccessor.CurrentIdentity;
revisionData.UserId = identity.UserId;
revisionData.EmployeeId = identity.EmployeeId;
revisionData.UserName = identity.Name;
}
}
Envers decides wich RevisionListener
to use depending on the RevisionEntity
attribute your class is decorated with:
[RevisionEntity( typeof( RevisionListener ) )]
I am using the ServiceLocator pattern to inject my accessor into the RevisionListener
. Currently this is the only place where I have to use a ServiceLocator and really want to get rid of it.
Is there another, flexible way to inject my UserAccessor into the RevisionEntity?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,今天不能。
然而,这听起来是一个不错的功能。请在此处添加有关此问题的 JIRA 票证
http://nhibernate.jira.com/browse/NHE
没有考虑太多,我我认为让用户仅通过属性配置来完成此操作会非常困难(如果是这样,则需要在内部构建某种 IoC)。也许可以通过允许在“靠近 IntegrateWithEnvers 方法的某个地方”注入修订侦听器单例来完成。
问候
罗杰
No, you can't today.
However - it sounds like a nice feature. Please add a JIRA ticket about it here
http://nhibernate.jira.com/browse/NHE
Without giving it too much thoughts, I think it'll be pretty hard to enable users to do this with only attribute configuration though (if so, sort of an IoC needs to be built internally). Probably it can be accomplished by allowing to inject a revision listener singleton "somewhere close to IntegrateWithEnvers method".
Regards
Roger