MVC and WebApi extensions

If you use the MVC or WebApi extensions for MicroLite and you use an ISession or IReadOnlySession for every action (method) on your controllers, instead of applying the [MicroLiteSession] to each controller or method you can simply register it in GlobalFilters so that it is invoked for every controller action.

GlobalFilters.Filters.Add(new MicroLiteSessionAttribute());

You can still add a [MicroLiteSession] to specific controller actions if you want to use an Isolation Level or transaction style which differs from the default specified in GlobalFilters:

public class HomeController : MicroLiteController
{
    public ActionResult Index()
    {
        // For this action, this.Session will be resolved using the configuration of 
        // the MicroLiteSessionAttribute in GlobalFilters.
    }

    [MicroLiteSession(AutoManageTransaction = false)]
    public ActionResult Index2()
    {
        // For this action, we want to do something specific with the transaction so we add the
        // MicroLiteSessionAttribute to this method to override the default configuration.
        using (var transaction = this.Session.BeginTransaction())
        {
            ...
        }
    }
}
Advertisements

2 thoughts on “MVC and WebApi extensions

  1. Pingback: MVC Extension 3.1.0 released | MicroLite ORM

  2. Pingback: WebApi Extension 2.1.0 Released | MicroLite ORM

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s