当前位置: 动力学知识库 > 问答 > 编程问答 >

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>

网友答案:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: