Ajouter Interceptor par le web.config? NHibernate
-
19-09-2019 - |
Question
Je ne peux pas l'air de trouver un exemple où quelqu'un a ajouté un intercepteur via web.config - est-ce possible?
Et oui je sais sur les écouteurs d'événements et les utiliseront sur un autre projet - mais je voulais voir si je pouvais contourner avoir à injecter l'intercepteur dans le code - merci
La solution
Je ne pense pas qu'il est pris en charge mais vous pouvez facilement chercher et instancier intercepteurs d'une section de configuration personnalisée:
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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow