Nancy - Unable to resolve type: NHibernate.ISession -


my custombootstrapper looks below

public class custombootstrapper : defaultnancybootstrapper {     protected override nancyinternalconfiguration internalconfiguration     {                 {             //this tell nancy won't have in nhibernate assemblies implementations of our interfaces.             return nancyinternalconfiguration                 .default                 .withignoredassembly(asm => asm.fullname.startswith("nhibernate", stringcomparison.invariantculture))                 .withignoredassembly(asm => asm.fullname.startswith("fluent", stringcomparison.invariantculture))                 .withignoredassembly(asm => asm.fullname.startswith("iesi", stringcomparison.invariantculture));         }     }      protected override void configurerequestcontainer(tinyioccontainer container, nancycontext context)     {         base.configurerequestcontainer(container, context);         //container.register((c, p) => sessionfactory.opensession());         container.register(sessionfactory.opensession());     } } 

i have repository accepts isession constructor dependency. when run application error saying unable resolve type: nhibernate.isession

i can confirm that

  1. my bootstrapper picked nanacy
  2. the isession registration code executed
  3. i have tried commenting out .withignoredassembly(asm => asm.fullname.startswith("nhibernate", stringcomparison.invariantculture)) property internalconfiguration
  4. i error both of ways of registering component (one commented in code)

i have looked @ similar other questions on , none has helped far.

i've done sample project uses nh nancy. in bootstrapper set up:

  1. a beforerequest hook creates session , binds session context
  2. a afterrequest hook commits session
  3. an onerror hook rolls back

the code follows:

public class bootstrapper : windsornancybootstrapper {   // other stuff   protected override void applicationstartup(iwindsorcontainer container, ipipelines pipelines)   {     base.applicationstartup(container, pipelines);      // other setup      configurenhibernatesessionperrequest(container, pipelines);   }    private void configurenhibernatesessionperrequest(iwindsorcontainer container, ipipelines pipelines)   {     pipelines.beforerequest += ctx => createsession(container);     pipelines.afterrequest += ctx => commitsession(container);     pipelines.onerror += (ctx, ex) => rollbacksession(container);   }    private response rollbacksession(iwindsorcontainer container)   {     var sessionfactory = container.resolve<isessionfactory>();     if (currentsessioncontext.hasbind(sessionfactory))     {       var requestsession = sessionfactory.getcurrentsession();       requestsession.transaction.rollback();       currentsessioncontext.unbind(sessionfactory);       requestsession.dispose();     }     return null;   }    private response createsession(iwindsorcontainer container)   {     var sessionfactory = container.resolve<isessionfactory>();     var requestsession = sessionfactory.opensession();     currentsessioncontext.bind(requestsession);     requestsession.begintransaction();      return null;   }    private afterpipeline commitsession(iwindsorcontainer container)   {     var sessionfactory = container.resolve<isessionfactory>();     if (currentsessioncontext.hasbind(sessionfactory))     {       var requestsession = sessionfactory.getcurrentsession();       requestsession.transaction.commit();       currentsessioncontext.unbind(sessionfactory);       requestsession.dispose();     }     return null;   }     } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -