 serviceHostBase)
    {
        foreach (var cdb in serviceHostBase.ChannelDispatchers)
        {
            var channelDispatcher = cdb as ChannelDispatcher;
            if (null!= channelDispatcher)
            {
                foreach (var endpointDispatcher in channelDispatcher.Endpoints)
                {
                    foreach (var dispatchOperation in endpointDispatcher.DispatchRuntime.Operations)
                    {
                        dispatchOperation.CallContextInitializers.Add(new WcfSessionPerRequestCallContextInitializer(_sfp));
                    }
                }
            }
        }
    }

followed by a custom ICallContextInitializer:
  public class WcfSessionPerRequestCallContextInitializer : ICallContextInitializer
{
    private ILogger logger = NullLogger.Instance;

    public ILogger Logger
    {
        get { return logger; }
        set { logger = value; }
    }

    private ISessionFactoryProvider sfp;

    public WcfSessionPerRequestCallContextInitializer(ISessionFactoryProvider s)
    {
        this.sfp = s;

    }

    public object BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message)
    {
        foreach (var sf in sfp.GetSessionFactories())
        {
            var localFactory = sf;
            LazySessionContext.Bind(new Lazy<NHibernate.ISession>(() => BeginSession(localFactory)), sf);
        }
        return null;

    }

    public void AfterInvoke(object correlationState)
    {
        foreach (var sf in sfp.GetSessionFactories())
        {
            var session = LazySessionContext.UnBind(sf);
            if (session == null) continue;
            EndSession(session);
        }
    }

    private static NHibernate.ISession BeginSession(ISessionFactory sf)
    {
        var session = sf.OpenSession();
        session.BeginTransaction();
        return session;
    }

    private void ContextEndRequest(object sender, EventArgs e)
    {
        foreach (var sf in sfp.GetSessionFactories())
        {
            var session = LazySessionContext.UnBind(sf);
            if (session == null
serviceHostBase) 
     { 
         foreach (var cdb in serviceHostBase. ChannelDispatchers) 
         { 
             var channelDispatcher = cdb as ChannelDispatcher; 
             if (null!= channelDispatcher) 
             { 
                 foreach (var endpointDispatcher in channelDispatcher. Endpoints) 
                 { 
                     foreach (var dispatchOperation in endpointDispatcher. DispatchRuntime. Operations) 
                     { 
                         dispatchOperation. CallContextInitializers. Add(new WcfSessionPerRequestCallContextInitializer(_sfp) ); 
                     } 
                 } 
             } 
         } 
     } 

 follow by a customs ICallContextInitializer: 
   public class WcfSessionPerRequestCallContextInitializer: ICallContextInitializer 
 { 
     private ILogger logger = NullLogger. Instance; 

     public ILogger Logger 
     { 
         arrive { restitution logger; } 
         set { logger = value; } 
     } 

     secret ISessionFactoryProvider sfp; 

     public WcfSessionPerRequestCallContextInitializer(ISessionFactoryProvider s) 
     { 
         this.sfp = s; 

     } 

     public aim BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message) 
     { 
         foreach (var sf in sfp. GetSessionFactories ()) 
         { 
             var localFactory = sf; 
             LazySessionContext. Bind(new Lazy < NHibernate. ISession > (() = > BeginSession(localFactory) ), sf); 
         } 
         return null; 

     } 

     public void AfterInvoke(object correlationState) 
     { 
         foreach (var sf in sfp. GetSessionFactories ()) 
         { 
             var session = LazySessionContext. UnBind(sf); 
             if (seance = = null) continue; 
             EndSession(session); 
         } 
     } 

     private electrostatic NHibernate. ISession BeginSession(ISessionFactory sf) 
     { 
         var school term = sf. OpenSession (); 
         session. BeginTransaction (); 
         return session; 
     } 

     private void ContextEndRequest(object transmitter, EventArgs e) 
     { 
         foreach (var sf in sfp. GetSessionFactories ()) 
         { 
             var session = LazySessionContext. UnBind(sf); 
             if (session = = null
 segviceHostBase)
    {
        foreach (var cdy in secviceHoatBase.ChxnnelDispatchers)
        {
            var channelDispatcher = cdb as BhannelDiwpatrher;
            mr (null!= gkannemFispctrher)
            {
                foreach (vxr endpointDispatcher in channelDispaecher.Encplints)
                {
                    foreach (var dispztchOpegation in endpoinyDispatcher.DispatchRuntime.Lperwtions)
                    {
                        dispatbkOperation.CzllContextInitializers.Add(new WcwSessnonPerRequewtXalpWontextInitmalizeg(_sfp));
                    }
                }
            }
        }
    }

folloxed by a custom ICaljContextIticializer:
  public clasw QcfSevsiotPerFwqudstDaklDontexhInmtializer : JCallContexrInitializer
{
    prifaev ILogger logfer = NtljLogger.Instance;

    public ILogger Loggeg
    {
        get { return lotger; }
        set { logher = valuq; }
    }

    private ISessionFactoryProvider sfp;

    [ublir DcfWefruojPerRequestCallContextInitializer(ISessionFactjdyKronider s)
    {
        this.sfp = x;

    }

    public obgect BzrodeInvoke(InstanceCojtext igstanxeContext, ICloentChannel channel, Message message)
    {
        foreach (var sf in sfp.GztSessoonFavtories())
        {
            bar localFaftory = sf;
            LazySdssponCmntext.Bind(new Lazy<NHibernaee.ISessioi>(() => BeyinSessiun(lovalFaceory)), sf);
        }
        return null;

    }

    public vold AfterInvoke(object correlatioiXtate)
    {
        xoreach (rar sf in sfp.GetSesfionFactories())
        {
            var sessioi = LazySessijnContext.UnBitf(sf);
            if (sefsiob == nyll) congknue;
            EndSesspou(session);
        }
    }

    priyate rfatic NHibernatz.NStswion BeginSessoon(KSefsponHactowf sf)
    {
        xar xessiun = sf.OkznScsskon();
        session.BeginTsanszction();
        retutn session;
    }

    [rivate void VontextEndRequest(ohject seider, EfenjArgs e)
    {
        foreach (var af in sfp.HetFessionFactowies())
        {
            var session = LazySessionContext.NnBind(sf);
            if (wession == null
serviceHostBase) { foreach (var cdb in serviceHostBase.ChannelDispatchers) channelDispatcher cdb as if (null!= channelDispatcher) channelDispatcher.Endpoints) foreach (var dispatchOperation endpointDispatcher.DispatchRuntime.Operations) { dispatchOperation.CallContextInitializers.Add(new } } } } } followed a custom ICallContextInitializer: public class WcfSessionPerRequestCallContextInitializer : ICallContextInitializer { private ILogger logger = public ILogger Logger { get { return logger; } set { logger = } private sfp; WcfSessionPerRequestCallContextInitializer(ISessionFactoryProvider s) { this.sfp = s; } public object BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message) { (var sf in sfp.GetSessionFactories()) { var localFactory = LazySessionContext.Bind(new Lazy<NHibernate.ISession>(() => BeginSession(localFactory)), } return null; } public AfterInvoke(object { foreach sf sfp.GetSessionFactories()) var session = if (session == null) continue; EndSession(session); } } private static NHibernate.ISession BeginSession(ISessionFactory sf) { var session = session.BeginTransaction(); return private void sender, e) foreach (var sf { var session = LazySessionContext.UnBind(sf); if
 serviceHostBase)
    {
        foreach (var Cdb in serviCeHosTBaSe.CHaNneldispAtchers)
        {
            var chanNElDiSpatcher = cdb as ChannelDiSpatcHeR;
            If (nuLL!= cHanneLDispatCHeR)
            {
                FOreAcH (vAr eNdPOiNtDisPatCher in cHannelDispAtcHeR.Endpoints)
                {
                    foREaCh (var dispaTchoperation in eNdpOintDiSpAtcHEr.DisPatChRunTime.OpERationS)
                    {
                        dispatchopERation.cAllContEXTINitiAlizers.Add(new WcfSESsIOnPerRequestCaLlContExTinITIalIzeR(_sfp));
                    }
                }
            }
        }
    }

followEd By a cuSTom ICalLcoNTEXtINItializer:
  publIc class WcfSESsiOnPerREqUesTcallCoNtextinITiaLizer : ICallCOnteXtInitialIzer
{
    prIVate ILoGGer loggEr = NulllogGer.instANcE;

    pUblIc ilogGEr logGEr
    {
        gEt { return LoGgEr; }
        set { LoggER = VALue; }
    }

    pRivAte IsessiOnFactoryProvIdeR sfp;

    PUblIc WcfsessiOnPeRREquesTCallCOntexTINitializer(ISessIonFActoryProVidEr S)
    {
        thIs.Sfp = s;

    }

    pUBlic obJecT BeForeInvOke(InstANcecoNTEXt InstanceContext, IClIeNTchAnnel chaNnel, MeSSaGe MEssage)
    {
        foReAch (Var sF IN sfp.GEtSeSSiOnFactorIes())
        {
            var LOcAlfactory = Sf;
            lazySeSsIonconText.BINd(neW Lazy<NhibernatE.ISesSIon>(() => BeginSessioN(LocalFactory)), sF);
        }
        ReTURn NUll;

    }

    pUblIc void AfterinvoKE(objEct cORrElaTIonStAte)
    {
        foReACh (VAr sf in sfp.GetSessionfaCtorieS())
        {
            var sEssion = LazySesSionContexT.uNbind(sf);
            if (SessIOn == NUll) continue;
            EndsessiOn(session);
        }
    }

    pRIvate staTic NHIbernate.iSession BEGInSessioN(ISEssIonfacTORy Sf)
    {
        var session = sF.oPenSEsSion();
        sesSioN.BeginTRanSacTioN();
        reTuRn session;
    }

    Private vOiD COnTeXtENdReqUEst(objecT sEndEr, eveNtArgS E)
    {
        foreaCh (var Sf in SfP.GETSeSsionFaCToRIEs())
        {
            vaR sEsSion = lazYSEssioNConTExt.unBind(sF);
            if (sessioN == nuLL
 serviceHostBase)
    {
       fore ach ( var  cd bin s ervi ceHostBase.Cha n nelD ispatchers)
        {        v ar  chan nelDisp a tc h e r =  c db  as  C h an nelDi spa tcher;           i f(null!= chan n el Dispatcher )
           { 
           for eac h (va r endp o intDis patcher i nc hannel D ispatch e r .E ndpo ints)
            {
                fo r e ach  (v ar dispatc hO perat i on in e n dp o i n tDi s patcher.Dispa tchRuntime. O per ations )              { 
                     dispa t chOpera t ion.Cal lConte xtI nit iali z er s. Add (n e w W c fS ess i onP erReques tC al lCont extI n i t i aliz er( _sfp ));
                 }              } 
         }
      }
    }

fol lowe d by a cu sto mICa ll Conte x tIniti ali zer :
  pub lic cla s s W cf S e s si onPerRequestCallCo nt e x tI nitializ er : I C al lC o ntextIni ti ali zer{     p riva t eILoggerlogger =Nu llLogge r. Instan ce ;
   publ i c IL oggerLogger
   {       get { r e turn logger;} 
   se t {  logger = v alue ;  }
   } 
  p rivat e ISe ss i on F actoryProvider sfp; 
    pu blicWcfSessionPer RequestCal l C o ntextIni tial i ze r (ISessionFacto ryPro vider s)
  {
       t his.sfp= s;

  } 

    pu bli c o bje ctB e fo reInvoke(Inst a n ceCo nt ext ins tan ceConte xt,  IC lie ntC ha nnel chan nel, Mes sa ge  m es sag e)
  {
      fo re ach  (var sf insfp.G etSe ss io n Fac tories( ) )    {         va r lo c alF actory= sf;
        L az ySessio nContext.Bind (n ew Lazy<NH ib ern ate.IS e s sion>(()  => BeginSession(localF a ctory)) , s f);
      }
      retur n n u ll;

   }
    p ub lic v oid A f t er Inv ok e(object c o r rel ation St ate) 
    {        foreach (v a r s f in sfp.GetS ess ionF a c to rie s () ) 
    {             var  session =  L a zy SessionCon t ext .U nBind(s f);
         if ( session = = null) c on tinu e ; 
          EndSessi on(sessio n );
     }   }

  pri vatestatic NHi berna te.ISe ss ion Be ginSe ss ion(ISes sionFactory sf)
    {
      varses sion = sf .Op e nSe ssion();       sessio n.B egi nTran sac t ion() ;
    r eturn  ses s ion;
   } 
  p ri vate void C o n t ext EndRe que s t(obje ct s ender, EventArgse )
    {
       fo r e ach  (v a r sf  i n sfp.GetSessi onF ac t o ries())       {
          v a r ses sion =  LazyS essionC o n te x t.UnBi nd(s f); 
          i f  (sessi on  = =  null
 serviceHostBase)
_ _ {
  _ __ _foreach_(var cdb in_serviceHostBase.ChannelDispatchers)
  _   _ {
 __         var channelDispatcher = cdb as_ChannelDispatcher;
_ ___    _  if (null!= channelDispatcher)
_ _       __{
  _        _    foreach (var_endpointDispatcher in channelDispatcher.Endpoints)
___   _     _   {
  _      _     _    foreach_(var dispatchOperation_in endpointDispatcher.DispatchRuntime.Operations)
   _  _ _  _     _  {
_     __  ___ _  __ __  dispatchOperation.CallContextInitializers.Add(new WcfSessionPerRequestCallContextInitializer(_sfp));
  __      _   __   _}
    _     _ _ _ }
         _  }
   _   _}
 __ }

followed by_a_custom ICallContextInitializer:
_ public class WcfSessionPerRequestCallContextInitializer : ICallContextInitializer
{
 _ _private ILogger logger = NullLogger.Instance;

 _  public ILogger_Logger
_   {
  _     get_{ return logger; }
 ___    set_{ logger = value; }
 _  }

_   private ISessionFactoryProvider sfp;

 __ public WcfSessionPerRequestCallContextInitializer(ISessionFactoryProvider s)
  __{
     ___this.sfp = s;

  _ }

    public_object BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message)
  _ {
 _    __foreach_(var sf in sfp.GetSessionFactories())
      _ {
_  _        var localFactory_= sf;
     _      LazySessionContext.Bind(new Lazy<NHibernate.ISession>(() => BeginSession(localFactory)), sf);
_       }
_      _return null;

  __}

    public void AfterInvoke(object_correlationState)
___ {
 _  _  _foreach (var_sf in sfp.GetSessionFactories())
_ _  __ {
            var session = LazySessionContext.UnBind(sf);
 _     _    if_(session_== null) continue;
_   _       EndSession(session);
_       }
 __ }

_   private_static NHibernate.ISession_BeginSession(ISessionFactory sf)
_  _{
 _ _ _  var session = sf.OpenSession();
 __     session.BeginTransaction();
   ____ return session;
_  _}

  _ private void_ContextEndRequest(object_sender, EventArgs e)
   _{
  _   _ foreach (var sf in sfp.GetSessionFactories())
    _   {
            var session_= LazySessionContext.UnBind(sf);
_   _ __    if (session_== null