通过DI配置Envers RevisionListener [英] Configure an Envers RevisionListener via DI

查看:110
本文介绍了通过DI配置Envers RevisionListener的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了向我们的应用程序添加审核跟踪,我们决定使用NHibernate.Envers.为了允许应用程序特定版本的修订,DefaultRevisionEntity扩展了用户特定数据.

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根据您的班级装饰的RevisionEntity属性来决定使用哪个RevisionListener:

Envers decides wich RevisionListener to use depending on the RevisionEntity attribute your class is decorated with:

[RevisionEntity( typeof( RevisionListener ) )]

我正在使用ServiceLocator模式将访问器注入到RevisionListener中.当前,这是我唯一需要使用ServiceLocator并真正希望摆脱它的地方.

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.

是否存在另一种灵活的方式将UserAccessor注入RevisionEntity?

Is there another, flexible way to inject my UserAccessor into the RevisionEntity?

推荐答案

不,您今天不能.

但是-听起来不错.请在此处添加一张JIRA票 http://nhibernate.jira.com/browse/NHE

However - it sounds like a nice feature. Please add a JIRA ticket about it here http://nhibernate.jira.com/browse/NHE

如果不考虑太多,我想让用户仅使用属性配置就很难做到这一点(如果是这样,则需要在内部构建某种IoC).可能可以通过允许在接近IntegrateWithEnvers方法的地方"插入修订侦听器单例来实现.

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".

问候 罗杰

这篇关于通过DI配置Envers RevisionListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆