Yesterday I showed the AuditInterceptor we are using in one of my applications. Maybe you noticed that we were using dependency injection:
Important to notice is that we are injecting a scoped dependency that contains the current user id(through the IUserFactory).
The trick to get this working is to set the interceptor when the session is created.
Therefore we register our IInterceptor implementation in the IoC container(Autofac in our situation):
Then when we construct a new session instance we’ll get the IInterceptor from the container and link it to the session: