Created
March 8, 2016 17:13
-
-
Save oguzhaneren/abe49157875a9af4477a to your computer and use it in GitHub Desktop.
Using controllers from an external assembly in ASP.NET Web API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class WebApiConfig | |
| { | |
| public static void Register(HttpConfiguration config) | |
| { | |
| // Web API configuration and services | |
| // Configure Web API to use only bearer token authentication. | |
| config.SuppressDefaultHostAuthentication(); | |
| config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); | |
| config.Services.Replace(typeof(IAssembliesResolver),new DynamicAssemblyResolver()); | |
| // Web API routes | |
| config.MapHttpAttributeRoutes(); | |
| config.Routes.MapHttpRoute( | |
| name: "DefaultApi", | |
| routeTemplate: "api/{controller}/{id}", | |
| defaults: new { id = RouteParameter.Optional } | |
| ); | |
| } | |
| } | |
| public class DynamicAssemblyResolver | |
| :IAssembliesResolver | |
| { | |
| public ICollection<Assembly> GetAssemblies() | |
| { | |
| return AppDomain.CurrentDomain.GetAssemblies(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment