-
Notifications
You must be signed in to change notification settings - Fork 1
Home
In order to use the WebApi extension for the MicroLite ORM framework, you need to reference it in your solution. The easiest way to do this is install it via NuGet (if you are unfamiliar with NuGet, it's a package manager for Visual Studio - visit nuget.org for more information).
Install-Package MicroLite.Extensions.WebApi
In the WebApiConfig
class in the App_Start
folder of your project, register the action filters. Only add the ones you want based upon the behaviour they introduce.
public static void Register(HttpConfiguration config)
{
...
// Add the MicroLite filters in the following order (for the ones you choose to use)
config.Filters.Add(new ValidateModelNotNullAttribute());
config.Filters.Add(new ValidateModelStateAttribute());
config.Filters.Add(new MicroLiteSessionAttribute("ConnectionName"));
config.Filters.Add(new AutoManageTransactionAttribute());
}
See the following pages for further details about the attributes:
- ValidateModelNotNullAttribute
- ValidateModelStateAttribute
- MicroLiteSessionAttribute
- AutoManageTransactionAttribute
Create a MicroLiteConfig
class in your App_Start
folder using the following template:
public static class MicroLiteConfig
{
public static void ConfigureConnection()
{
// Load any MicroLite extensions
Configure
.Extensions() // if you are also using a logging extension, register it first
.WithWebApi();
}
public static void ConfigureExtensions()
{
// Create session factories for any connections
Configure
.Fluently()
.For...Connection("ConnectionName")
.CreateSessionFactory();
}
}
Call the MicroLiteConfig
from the application start method in your Global.asax
:
protected void Application_Start()
{
// Register routes, bundles etc, then:
WebApiConfig.Register(GlobalConfiguration.Configuration);
...
// Always configure extensions before connections.
MicroLiteConfig.ConfigureExtensions();
MicroLiteConfig.ConfigureConnection();
}
The implement IHaveSession
or IHaveReadOnlySession
- either directly or by inheriting from the MicroLiteApiController
or MicroLiteReadOnlyApiController
.