NHibernate カスタム コンテキスト (ICurrentSessionContext) を実装しました。このコンテキストでは、NHibernate セッションを挿入するため、呼び出しパターンごとにセッションを設定します。さて、現在ログインしているユーザーの userId を取得するインターセプターを作成しました。今私はこれを行います:
public ISession CurrentSession()
{
// Get the WCF InstanceContext:
var contextManager = OperationContext.Current.InstanceContext.Extensions.Find<NHibernateContextManager>();
if (contextManager == null)
{
throw new InvalidOperationException(
@"There is no context manager available.
Check whether the NHibernateContextManager is added as InstanceContext extension.
Make sure the service is being created with the NhServiceHostFactory.
This Session Provider is intended only for WCF services.");
}
var session = contextManager.Session;
AuditLogInterceptor interceptor = new AuditLogInterceptor();
if (session == null)
{
session = this._factory.OpenSession(interceptor);
interceptor.Session = session;
contextManager.Session = session;
}
return contextManager.Session;
}
私の AuditLogInterceptor は UserId を受け取りますが、この userId を取得する方法 (どこから) がわかりません。