Skip to content

Instantly share code, notes, and snippets.

@HenrikFrystykNielsen
Created November 5, 2015 06:01
Show Gist options
  • Save HenrikFrystykNielsen/a0b9a51645633b7919a1 to your computer and use it in GitHub Desktop.
Save HenrikFrystykNielsen/a0b9a51645633b7919a1 to your computer and use it in GitHub Desktop.
WebHookSender: Register custom WebHookManager using Autofac
public static void Register(HttpConfiguration config)
{
// Web API configuration and services
// Web API routes
config.MapHttpAttributeRoutes();
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
// Load basic support for sending WebHooks
config.InitializeCustomWebHooks();
// Load Azure Storage or SQL for persisting subscriptions
config.InitializeCustomWebHooksAzureStorage();
//config.InitializeCustomWebHooksSqlStorage();
// Load Web API controllers for managing subscriptions
config.InitializeCustomWebHooksApis();
// Initialize Autofac
ContainerBuilder builder = new ContainerBuilder();
// Create custom WebHookManager and register it with Autofac
ILogger logger = config.DependencyResolver.GetLogger();
IWebHookStore store = config.DependencyResolver.GetStore();
IWebHookManager manager = new WebHookManager(store, logger, new TimeSpan[] { }, null);
builder.RegisterInstance(manager).As<IWebHookManager>().SingleInstance();
// Register MVC and Web API controllers
Assembly currentAssembly = Assembly.GetExecutingAssembly();
builder.RegisterApiControllers(currentAssembly);
builder.RegisterControllers(currentAssembly);
// Build the container and set it as the dependency resolver for both MVC and Web API
IContainer container = builder.Build();
DependencyResolver.SetResolver(new AutofacDependencyResolver(container));
config.DependencyResolver = new AutofacWebApiDependencyResolver(container);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment