Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 在NHibernate拦截器中访问当前请求上下文_.net_Nhibernate_Interceptor_Unit Of Work_Sharp Architecture - Fatal编程技术网

.net 在NHibernate拦截器中访问当前请求上下文

.net 在NHibernate拦截器中访问当前请求上下文,.net,nhibernate,interceptor,unit-of-work,sharp-architecture,.net,Nhibernate,Interceptor,Unit Of Work,Sharp Architecture,我正在使用SharpArchitecture,并试图在基础架构层为NHibernate创建一个简单的试听器 现在,我的问题是使当前的请求细节可以从拦截器中访问。这包括当前用户和服务器接收活动请求的日期/时间 我应该使用某种UnitOfWork模式吗?如果是这样,使UnitOfWork对象可用于拦截器代码的好方法是什么?据我所知,获取当前用户的最佳位置是: System.Threading.Thread.CurrentPrincipal.Identity.Name 我还需要获取当前请求的日期/时

我正在使用SharpArchitecture,并试图在基础架构层为NHibernate创建一个简单的试听器

现在,我的问题是使当前的请求细节可以从拦截器中访问。这包括当前用户和服务器接收活动请求的日期/时间


我应该使用某种UnitOfWork模式吗?如果是这样,使UnitOfWork对象可用于拦截器代码的好方法是什么?

据我所知,获取当前用户的最佳位置是:

System.Threading.Thread.CurrentPrincipal.Identity.Name

我还需要获取当前请求的日期/时间,并决定最好创建一个自定义的
IPrincipal
,该属性具有
CurrentDateTime
属性,然后在Global.asax
OnAuthenticated
或我的MVC ActionFilter中设置自定义主体。

谢谢!我决定在应用程序启动时配置NHibernate时,将“IAuditInfoProvider”对象传递给拦截器构造函数。目前还不确定我将如何实现它,但至少它允许我在以后更改它,而不会影响拦截器代码。我正在考虑创建一个自定义上下文对象来实现这个(和其他)接口,它在Begin/EndRequest中被修改,并被注入到带有我正在使用的IoC容器的对象中。我对MVC和SharpArchitecture还不太了解,所以这只是一个想法。当我解决同样的问题时,我不知道如何摆脱静态属性/类的使用。您还必须处理线程问题。