Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class WebApiApplication : System.Web.HttpApplication {
[ImportMany]
List<IComposableApiMetadata> m_composers;
private CompositionContainer m_container;
protected void Application_Start() {
var catalog = new AggregateCatalog();
var servicesFolder = @"C:\dllFolder";
catalog.Catalogs.Add(new DirectoryCatalog(servicesFolder));
m_container = new CompositionContainer(catalog);
m_container.ComposeParts(this);
var builder = new ContainerBuilder();
foreach (var composableApiMetadata in m_composers) {
composableApiMetadata.Compose(builder);
builder.RegisterApiControllers(composableApiMetadata.ApiAssembly());
}
var container = builder.Build();
var resolver = new AutofacWebApiDependencyResolver(container);
GlobalConfiguration.Configuration.DependencyResolver = resolver;
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment