在 NHibernate 拦截器中访问当前请求上下文
我正在使用 SharpArchitecture,并尝试在基础设施层中为 NHibernate 创建一个简单的 AuditInterceptor。
现在,我的问题是使当前的请求详细信息可以从拦截器内访问。这包括当前用户和服务器收到活动请求的日期/时间。
我应该使用某种 UnitOfWork 模式吗?如果是这样,使 UnitOfWork 对象可供拦截器代码使用的好方法是什么?
I'm playing around with SharpArchitecture and I'm trying to create a simple AuditInterceptor for NHibernate in the Infrastructure layer.
Now, my problem is to make the current request details accessible from within the interceptor. This includes the current user and the date/time at which the server received the active request.
Should I be using some kind of UnitOfWork pattern? If so, what is a good way of making the UnitOfWork object available to the interceptor code?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我发现,获取当前用户的最佳位置是:
我还需要获取当前请求的日期/时间,并决定最好创建一个自定义的 IPrincipal ,其中有一个 CurrentDateTime 属性,然后我在 Global.asax OnAuthenticated 或 MVC ActionFilter 中设置自定义主体。
As far as I have found out the best place to get the current user is:
I had a need to also get the Date/Time of the current request and decided it was best to create a custom
IPrincipal
which had aCurrentDateTime
property and then I set the custom principal either in Global.asaxOnAuthenticated
or in my MVC ActionFilter.