Patrick Coelho
Patrick Coelho

Reputation: 168

How to use a Interceptor from NHibernate config XML file?

I want to use a nhibernate interceptor (overriding EmptyInterceptor) without code change.

It's possible to do it from XML config file?

My EmptyInterceptor override class:

public class QueryNumberInterceptor : EmptyInterceptor {
        public override SqlString OnPrepareStatement(SqlString sql) {
            return base.OnPrepareStatement(sql);
        }
}

My XML config file:

<config>
    <add key="connection.driver_class" value="NHibernate.Driver.SqlClientDriver, NHibernate"/>
    <add key="dialect" value="NHibernate.Dialect.MsSql2008Dialect, NHibernate"/>
    <add key="connection.connection_string" value="ConnectionString = ${MainConnection}"/>
    <add key="show_sql" value="true"/>
</config>

Upvotes: 2

Views: 526

Answers (1)

Stefan Steinegger
Stefan Steinegger

Reputation: 64628

AFAIK, you can't inject an interceptor with the configuration file.

But you could register an event listener. You can do pretty the same with event listeners as you can with the interceptor. But its a different concept and therefore looks different.

Upvotes: 1

Related Questions