문제

Web.config를 통해 누군가가 인터셉터를 추가 한 예를 찾을 수없는 것 같습니다. 가능합니까?

그리고 네, 이벤트 청취자에 대해 알고 다른 프로젝트에서 사용할 것입니다. 그러나 코드에 인터셉터를 주입 해야하는지 알고 싶었습니다. 감사합니다.

도움이 되었습니까?

해결책

나는 그것이 지원되었다고 생각하지 않지만 사용자 정의 구성 섹션에서 쉽게 가져오고 인스턴스화 할 수 있습니다.

NHibernate.Cfg.Configuration cfg = ...
var interceptors = (NameValueCollection) ConfigurationManager.GetSection("nhibernate.interceptors");
foreach (string k in interceptors)
    cfg.SetInterceptor((IInterceptor) Activator.CreateInstance(Type.GetType(k)));

web.config :

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
 <configSections>
   <section name="nhibernate.interceptors" type="System.Configuration.NameValueSectionHandler, System" />
 </configSections>
 <nhibernate.interceptors>
    <add key="MyApp.Interceptors.SomeInterceptor, MyApp" value=""/>
    <add key="MyApp.Interceptors.AnotherInterceptor, MyApp" value=""/>
 </nhibernate.interceptors>
</configuration>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top