I have the following connection scheme for NHibernate ISession in Autofac for an ASP.NET application:
builder.RegisterAdapter<ISessionFactory, ISession>(factory => factory.OpenSession()) .InstancePerHttpRequest() .OnActivated(activatedArgs => { var session = activatedArgs.Instance; session.BeginTransaction(); }) .OnRelease(session => { if (session.Transaction != null && session.Transaction.IsActive) { try { session.Transaction.Commit(); } catch(Exception e) { session.Transaction.Rollback(); throw; } } });
Will the session be properly deleted even with an excluded throw to the commit? Is this the correct use of ISession with autofac?
Cannot be thrown in Dispose()not very well with Autofac. Proper disposal of instances of other components is not guaranteed.
Dispose()
, - , WCF , . , Dispose() , .
Edit:
- , try/catch Autofac. , OnRelease() ? . - Autofac, ? , , .
OnRelease()
, , .
NHibernate ISession Autofac, Dispose(), . finally catch .
Source: https://habr.com/ru/post/1795082/More articles:Java Concurrency - modern examples, tutorials, excersies, turn-based applications - javaspring AbstractExcelView and IE - springIs it possible to set pre-processor conditions in a macro? - c ++presentRenderbuffer: GL_RENDERBUFFER_OES takes a lot of time - iphoneGlFlush () time varies from frame to frame with the same content on iPhone - iphoneThe size of the widget is different when testing at the local and publishing level - the same phone - androidRails associations across multiple levels - ruby-on-railsHow to store user actions on the Asp.net Mvc website? - c #java.io.EOFException: Unexpected end of ZLIB input stream - javahttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1795087/java-generics-gain-access-to-parameters&usg=ALkJrhgn_HZAwSQqG6DtBpZDF6kkTRpNaAAll Articles