Ejemplo n.º 1
0
        // This code configures Web API contained in the class Startup, which is additionally specified as the type parameter in WebApplication.Start
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host.
            HttpConfiguration config = new HttpConfiguration();

            var model = GetODataModel();

            config.Count().Filter().OrderBy().Expand().Select().MaxTop(null);
            config.MapODataServiceRoute(
                routeName: "ODataRoute",
                routePrefix: "odata",
                model: model);

            config.Routes.MapHttpRoute(
                name: "ControllersAndActions",
                routeTemplate: "{controller}/{action}",
                defaults: new { id = RouteParameter.Optional });
            config.Routes.MapHttpRoute(
                name: "ControllerOnly",
                routeTemplate: "{controller}");

            SwaggerConfig.Register(config);

            StructureMapDependencyResolver container = new StructureMapDependencyResolver();

            config.DependencyResolver = container;
            config.Formatters.JsonFormatter.SerializerSettings
            .ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            var json = config.Formatters.JsonFormatter;

            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            config.Formatters.Remove(config.Formatters.XmlFormatter);



            appBuilder.Use <Logger>();
            appBuilder.UseWebApi(config);
        }
Ejemplo n.º 2
0
        // This code configures Web API contained in the class Startup, which is additionally specified as the type parameter in WebApplication.Start
        public void Configuration(IAppBuilder appBuilder)
        {
            // Configure Web API for self-host.
            HttpConfiguration config = new HttpConfiguration();

            config.Routes.MapHttpRoute(
                name: "ControllersAndActions",
                routeTemplate: "{controller}/{action}",
                defaults: new { id = RouteParameter.Optional }
                );

            config.Routes.MapHttpRoute(
                name: "ControllerOnly",
                routeTemplate: "{controller}");

            StructureMapDependencyResolver container = new StructureMapDependencyResolver();

            config.DependencyResolver = container;
            config.Formatters.JsonFormatter.SerializerSettings
            .ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            appBuilder.Use <Logger>();
            appBuilder.UseWebApi(config);
        }