Created
July 16, 2016 14:57
-
-
Save kleberksms/ef439d298c7a32478405ffe8d524717a to your computer and use it in GitHub Desktop.
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 void Configuration(IAppBuilder app) | |
{ | |
var config = new HttpConfiguration(); | |
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); | |
WebApiConfig.ConfigureWebApi(config); | |
app.UseCors(CorsOptions.AllowAll); | |
var kernel = new Func<StandardKernel>(new Container().CreateKernel); | |
app.UseNinjectMiddleware(kernel).UseNinjectWebApi(config); | |
app.UseWebApi(config); | |
} | |
public static void ConfigureWebApi(HttpConfiguration config) | |
{ | |
config.MapHttpAttributeRoutes(); | |
SwaggerConfig.Register(config); | |
var formatters = config.Formatters; | |
formatters.Clear(); | |
formatters.Add(new JsonMediaTypeFormatter()); | |
var jsonFormatter = formatters.JsonFormatter; | |
var settings = jsonFormatter.SerializerSettings; | |
settings.Formatting = Formatting.Indented; | |
settings.ContractResolver = new CamelCasePropertyNamesContractResolver(); | |
settings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; | |
config.Routes.MapHttpRoute( | |
name: "DefaultApi", | |
routeTemplate: "api/{controller}/{id}", | |
defaults: new { id = RouteParameter.Optional } | |
); | |
} | |
public static void Register(HttpConfiguration config) | |
{ | |
config | |
.EnableSwagger(c => | |
{ | |
c.SingleApiVersion("v1", "Api"); | |
c.IncludeXmlComments(GetXmlCommentsPath()); | |
}) | |
.EnableSwaggerUi(c =>{ }); | |
} | |
private static string GetXmlCommentsPath() | |
{ | |
return AppDomain.CurrentDomain.BaseDirectory + "\\bin\\Api.XML"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment