本文整理汇总了C#中System.Net.Http.Formatting.JsonMediaTypeFormatter.AddQueryStringMapping方法的典型用法代码示例。如果您正苦于以下问题:C# JsonMediaTypeFormatter.AddQueryStringMapping方法的具体用法?C# JsonMediaTypeFormatter.AddQueryStringMapping怎么用?C# JsonMediaTypeFormatter.AddQueryStringMapping使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.Formatting.JsonMediaTypeFormatter
的用法示例。
在下文中一共展示了JsonMediaTypeFormatter.AddQueryStringMapping方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Register
public static void Register(HttpConfiguration config)
{
try
{
// Find assembly from path defined in web.config
var path = PayAtTable.API.Properties.Settings.Default.DataRepositoryAssembly;
var mappedPath = System.Web.Hosting.HostingEnvironment.MapPath(path);
Assembly assembly = Assembly.LoadFrom(mappedPath);
// Register data repository implementations with the IoC container
var container = TinyIoCContainer.Current;
container.Register(typeof(IOrdersRepository), LoadInstanceFromAssembly(typeof(IOrdersRepository), assembly)).AsPerRequestSingleton();
container.Register(typeof(ITablesRepository), LoadInstanceFromAssembly(typeof(ITablesRepository), assembly)).AsPerRequestSingleton();
container.Register(typeof(IEFTPOSRepository), LoadInstanceFromAssembly(typeof(IEFTPOSRepository), assembly)).AsPerRequestSingleton();
container.Register(typeof(ITendersRepository), LoadInstanceFromAssembly(typeof(ITendersRepository), assembly)).AsPerRequestSingleton();
container.Register(typeof(ISettingsRepository), LoadInstanceFromAssembly(typeof(ISettingsRepository), assembly)).AsPerRequestSingleton();
// Uncomment the following code to load a local data repository in this project rather than an external DLL
//container.Register<IOrdersRepository, DemoRepository>().AsPerRequestSingleton();
//container.Register<ITablesRepository, DemoRepository>().AsPerRequestSingleton();
//container.Register<IEFTPOSRepository, DemoRepository>().AsPerRequestSingleton();
//container.Register<ITendersRepository, DemoRepository>().AsPerRequestSingleton();
//container.Register<ISettingsRepository, DemoRepository>().AsPerRequestSingleton();
// Set Web API dependancy resolver
System.Web.Http.GlobalConfiguration.Configuration.DependencyResolver = new TinyIocWebApiDependencyResolver(container);
// Uncomment the following code to support XML
//var xmlMediaTypeFormatter = new XmlMediaTypeFormatter();
//xmlMediaTypeFormatter.AddQueryStringMapping("format", "xml", "text/xml");
//config.Formatters.Add(xmlMediaTypeFormatter);
// Add JSON formatter
var jsonMediaTypeFormatter = new JsonMediaTypeFormatter() { SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings() { NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore } };
jsonMediaTypeFormatter.AddQueryStringMapping("format", "json", "application/json");
config.Formatters.Add(jsonMediaTypeFormatter);
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
// Web API2 routes
config.MapHttpAttributeRoutes();
// Uncomment the following code to support WEB API v1 routing
//config.Routes.MapHttpRoute(
// name: "DefaultApi",
// routeTemplate: "api/{controller}/{id}",
// defaults: new { id = RouteParameter.Optional }
//);
// Uncomment the following to add a key validator to the message pipeline.
// This will check that the "apikey" parameter in each request matches an api key in our list.
config.MessageHandlers.Add(new ApiKeyHandler("key"));
}
catch (Exception ex)
{
log.ErrorEx((tr) => { tr.Message = "Exception encounted during configuration"; tr.Exception = ex; });
throw ex;
}
}