Pregunta

BACKGROUND:

Creating the start of a web app with NH3 using HttpModule to manage the creation/commit/rollback of the transaction and session. In a scenario where an error occurs, i would like to return a simple message back to the user, but rollback the transaction. Hooking into the context.Error event, allows easy rollback upon an exception, however, this will never be called since exceptions are being caught, displaying a friendly message to the user.

Due to the issue above i am going to create a custom unit of work scenario, and store it in the Http Context for the request. If an error occurs, set a RollbackRequired flag, and have the unit of work perform rollback based on this. Storing in the session in the HttpContext - Is this the same as using CurrentSessionContext?

If anyone has other thoughts i'd be great.

Thanks.

¿Fue útil?

Solución

Storing in the session in the HttpContext - Is this the same as using CurrentSessionContext?

Yes, it is pretty much what the WebSessionContext thing does.

If anyone has other thoughts i'd be great.

If you're catching the exception, why don't you roll it back as well?

ISession.Transaction.WasCommitted and ISession.ITransaction.WasRolledback give you an indication of whether the transaction was rolled back / committed. You can commit it in your HttpModule if it's not rolled back and not committed.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top