Skip to the content.

Unit of Work

The unit of work pattern for ASP.NET Core is implemented using a combination of TransactionAttribute and AutoTransactionHandler.

TransactionAttribute is a marker attribute used to configure the unit of work for a controller action; it does not implement any transaction management itself. It configures the following parameters:

AutoTransactionHandler is an MVC action filter that wraps a controller action in a transaction, using the settings from the [Transaction] attribute applied to that action or its controller. It commits the transaction on success and rolls it back on an unhandled exception (and, optionally, on a model-validation error).

Best practices