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
- my bootstrapper picked nanacy
- the
isession
registration code executed - i have tried commenting out
.withignoredassembly(asm => asm.fullname.startswith("nhibernate", stringcomparison.invariantculture))
propertyinternalconfiguration
- 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:
- a beforerequest hook creates session , binds session context
- a afterrequest hook commits session
- 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
Post a Comment