J'ai implémenté le contexte personnalisé NHibernate (ICurrentSessionContext). Dans ce contexte, j'injecte la session NHibernate de sorte que je dispose de la configuration Session par appel. Ok, maintenant j'ai fait un intercepteur qui prend userId de l'utilisateur actuellement connecté. Maintenant, je fais ceci:comment obtenir un ID utilisateur authentifié à partir de wcf dans nhibernate
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;
}
Mon AuditLogInterceptor prend UserId mais je ne sais pas comment (où) pour obtenir ce userId.