Skip to content

Instantly share code, notes, and snippets.

@jamesmundy
Last active November 19, 2018 23:53
Show Gist options
  • Save jamesmundy/878a45cb829531157452e4209b234b4f to your computer and use it in GitHub Desktop.
Save jamesmundy/878a45cb829531157452e4209b234b4f to your computer and use it in GitHub Desktop.
An example WebAPIConfig file used to configure a bot framework web api.
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
var store = new TableBotDataStore(ConfigurationManager.ConnectionStrings["StorageConnectionString"]
.ConnectionString);
Conversation.UpdateContainer(builder => {
builder.RegisterModule(new DefaultExceptionMessageOverrideModule());
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
.As<IBotDataStore<BotData>>()
.AsSelf()
.SingleInstance();
// Register your Web API controllers.
builder.RegisterApiControllers(Assembly.GetExecutingAssembly());
builder.RegisterWebApiFilterProvider(config);
});
// Set the dependency resolver to be Autofac.
config.DependencyResolver = new AutofacWebApiDependencyResolver(Conversation.Container);
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute("DefaultApi",
"api/{controller}/{id}",
new
{
id = RouteParameter.Optional
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment