public static IAppBuilder UseWishlistApi(this IAppBuilder app, WishlistApiOptions options)
        {
            var config = app.ConfigureContainer(new HttpConfiguration());

            app.UseWebApi(WebApiConfig.Configure(config, options));
            return app;
        }
Esempio n. 2
0
        public static HttpConfiguration Configure(HttpConfiguration config, WishlistApiOptions options)
        {
            if (options == null) throw new ArgumentNullException(nameof(options));

            options.Configure?.Invoke(config);
            config.MapHttpAttributeRoutes(new InheritedDirectRouteProvider());
            //config.Routes.MapHttpRoute(
            //     name: "DefaultApi",
            //     routeTemplate: "api/{controller}/{id}",
            //     defaults: new { id = RouteParameter.Optional }
            //);
            //config.MapRestControllerRouting(typeof(MyListController));
            //config.MapRestControllerRouting(typeof(MyListWishController));
            config.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver();

            return config;
        }
Esempio n. 3
0
        public void Configuration(IAppBuilder appBuilder)
        {
            JwtSecurityTokenHandler.InboundClaimTypeMap = new Dictionary<string, string>();
            appBuilder.UseCors(CorsOptions.AllowAll);

            appBuilder.Map("/wishlist", inner =>
            {
                //inner.UseIdentityServerBearerTokenAuthentication(new IdentityServerBearerTokenAuthenticationOptions
                //{
                //    TokenProvider = new QueryStringOAuthBearerProvider("api_key"),
                //    Authority = "https://localhost:44344",
                //    RequiredScopes = new[] { "write" }
                //});
                var wishlistApiOptions = new WishlistApiOptions();
                wishlistApiOptions.Configure = configuration =>
                {
                    configuration
                        .EnableSwagger(c =>
                        {
                            c.ApiKey("Authorization").In("header");

                            c.RootUrl(o => o.RequestUri.GetLeftPart(UriPartial.Authority) +
                                           o.GetRequestContext().VirtualPathRoot.TrimEnd('/'));
                            c.SingleApiVersion("v1", "A title for your API");

                            var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
                            var commentsFileName = typeof(WishlistApiOptions).Assembly.GetName().Name + ".XML";
                            var commentsFile = Path.Combine(baseDirectory, commentsFileName);

                            c.IncludeXmlComments(commentsFile);
                        })
                        .EnableSwaggerUi();
                };
                inner.UseWishlistApi(wishlistApiOptions);
            });
        }