// This code configures Web API. The Startup class is specified as a type // parameter in the WebApp.Start method. public void Configuration(IAppBuilder appBuilder) { // Configure Web API for self-host. HttpConfiguration config = new HttpConfiguration(); config.MapODataServiceRoute("odata", "odata", GetEdmModel()); // create the formatters with the custom serializer provider and use them in the configuration. var odataFormatters = ODataMediaTypeFormatters.Create(new CustomODataSerializerProvider(), new DefaultODataDeserializerProvider()); config.Formatters.InsertRange(0, odataFormatters); appBuilder.UseWebApi(config); }
public static void ConfigurationWithFormatters(IAppBuilder appBuilder, Action <SwaggerDocsConfig> unitTestConfigs, params Type[] targetControllers) { var config = new HttpConfiguration { IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always }; config = ConfigureWebApi(config); config = ConfigureOData(appBuilder, targetControllers, config, unitTestConfigs); config.Formatters.InsertRange(0, ODataMediaTypeFormatters.Create(new NullSerializerProvider(), new DefaultODataDeserializerProvider())); config.EnsureInitialized(); }
public static void UpdateConfiguration(HttpConfiguration configuration) { configuration.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; configuration.Formatters.InsertRange(0, ODataMediaTypeFormatters.Create( new CustomODataSerializerProvider(new MockContainer()), new DefaultODataDeserializerProvider(new MockContainer()))); var routingConventions = ODataRoutingConventions.CreateDefault(); routingConventions.Insert(4, new GetRefRoutingConvention()); configuration.MapODataServiceRoute( "EntityReferenceLinks", "EntityReferenceLinks", GetEdmModel(configuration), new DefaultODataPathHandler(), routingConventions); }
/// <summary> /// Maps the OData service. /// </summary> /// <param name="config">The current HTTP configuration.</param> /// <param name="builder">The EDM model builder.</param> /// <param name="routeName">The name of the route (<see cref="DataObjectRoutingConventions.DefaultRouteName"/> be default).</param> /// <param name="routePrefix">The route prefix (<see cref="DataObjectRoutingConventions.DefaultRoutePrefix"/> be default).</param> /// <returns>OData service registration token.</returns> public static ManagementToken MapODataServiceDataObjectRoute( this HttpConfiguration config, IDataObjectEdmModelBuilder builder, string routeName = DataObjectRoutingConventions.DefaultRouteName, string routePrefix = DataObjectRoutingConventions.DefaultRoutePrefix) { Contract.Requires <ArgumentNullException>(config != null); Contract.Requires <ArgumentNullException>(builder != null); Contract.Requires <ArgumentNullException>(routeName != null); Contract.Requires <ArgumentException>(routeName != string.Empty); Contract.Requires <ArgumentNullException>(routePrefix != null); Contract.Requires <ArgumentException>(routePrefix != string.Empty); // Model. var model = builder.Build(); // Routing. var pathHandler = new ExtendedODataPathHandler(); var routingConventions = DataObjectRoutingConventions.CreateDefault(); var route = config.MapODataServiceRoute(routeName, routePrefix, model, pathHandler, routingConventions); // Controllers. var registeredActivator = (IHttpControllerActivator)config.Services.GetService(typeof(IHttpControllerActivator)); var fallbackActivator = registeredActivator ?? new DefaultHttpControllerActivator(); config.Services.Replace(typeof(IHttpControllerActivator), new DataObjectControllerActivator(fallbackActivator)); // Formatters. var customODataSerializerProvider = new CustomODataSerializerProvider(); var extendedODataDeserializerProvider = new ExtendedODataDeserializerProvider(); var odataFormatters = ODataMediaTypeFormatters.Create(customODataSerializerProvider, extendedODataDeserializerProvider); config.Formatters.InsertRange(0, odataFormatters); config.Properties[typeof(CustomODataSerializerProvider)] = customODataSerializerProvider; // Token. var token = new ManagementToken(route, model); config.SetODataServiceToken(token); // Handlers. if (config.MessageHandlers.FirstOrDefault(h => h is PostPatchHandler) == null) { config.MessageHandlers.Add(new PostPatchHandler()); } return(token); }
private static FeaturedODataSerializerProvider GetOrAddFeaturedSerializationProvider(this HttpConfiguration configuration) { var serializerProvider = configuration.Formatters.OfType <ODataMediaTypeFormatter>().Select(f => f.SerializerProvider).OfType <FeaturedODataSerializerProvider>().FirstOrDefault(); if (serializerProvider != null) { return(serializerProvider); } serializerProvider = new FeaturedODataSerializerProvider(); var deserializerProvider = new DefaultODataDeserializerProvider(); var formatters = ODataMediaTypeFormatters.Create(serializerProvider, deserializerProvider); configuration.Formatters.InsertRange(0, formatters); return(serializerProvider); }
public static void Register(HttpConfiguration config) { // Web API routes config.MapHttpAttributeRoutes(); var builder = new ODataConventionModelBuilder(); builder.EntitySet <ApiPerson>("People"); builder.EntitySet <ApiContribution>("Contributions"); builder.EntitySet <ApiContributionFund>("Funds"); builder.EntitySet <ApiMeeting>("Meetings"); builder.EntitySet <ApiOrganization>("Organizations"); builder.EntitySet <ApiOrganizationMember>("OrganizationMembers"); builder.EntitySet <ApiChAiPerson>("ChAiPeople"); builder.EntitySet <ApiChAiGift>("ChAiGifts"); config.Count().Filter().OrderBy().Expand().Select().MaxTop(100); config.MapODataServiceRoute( routeName: "ODataApiRoot", routePrefix: "api", model: builder.GetEdmModel()); var builderlookup = new ODataConventionModelBuilder(); builderlookup.EntitySet <ApiLookup>("Campuses"); builderlookup.EntitySet <ApiLookup>("Genders"); builderlookup.EntitySet <ApiLookup>("MaritalStatuses"); builderlookup.EntitySet <ApiLookup>("FamilyPositions"); builderlookup.EntitySet <ApiLookup>("ContributionTypes"); builderlookup.EntitySet <ApiLookup>("BundleHeaderTypes"); config.MapODataServiceRoute( routeName: "ODataApiLookupRoute", routePrefix: "api/lookup", model: builderlookup.GetEdmModel()); config.Filters.Add(new ApiAuthorizeAttribute()); config.MessageHandlers.Add(new ApiMessageLoggingHandler()); // fix for XML support (use Accept: application/xml) var formatters = ODataMediaTypeFormatters.Create(); config.Formatters.InsertRange(0, formatters); var jsonFormatter = config.Formatters.OfType <JsonMediaTypeFormatter>().First(); jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); jsonFormatter.SerializerSettings.Formatting = Newtonsoft.Json.Formatting.Indented; }
public void GetMetadata_Returns_EdmModelFromSetODataFormatter() { IEdmModel model = new EdmModel(); IEnumerable <ODataMediaTypeFormatter> oDataFormatters = ODataMediaTypeFormatters.Create(model); HttpConfiguration configuration = new HttpConfiguration(); configuration.Formatters.InsertRange(0, oDataFormatters); ODataMetadataController controller = new ODataMetadataController(); controller.Request = new HttpRequestMessage(); controller.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = configuration; IEdmModel responseModel = controller.GetMetadata(); Assert.Equal(model, responseModel); }
public static void Register(HttpConfiguration config) { config.MapHttpAttributeRoutes(); HttpServer APIServer = new HttpServer(config); config.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; config.Formatters.JsonFormatter.MaxDepth = 2048; config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; config.Services.Replace(typeof(IExceptionHandler), new CustomExceptionHandler()); var odataFormatters = ODataMediaTypeFormatters.Create(new ODataSerialzer(), new ODataDeserialzer()); config.Formatters.Clear(); config.Formatters.AddRange(odataFormatters); config.MapODataServiceRoute(routeName: "OData", routePrefix: "", model: APIConfiguration.GetModel(), batchHandler: new DefaultODataBatchHandler(APIServer)); }
/// <summary> /// Inserts the RESTier specific formatters to the controller. /// </summary> /// <param name="controllerSettings">The controller settings.</param> /// <param name="controllerDescriptor">The controller descriptor.</param> public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) { Ensure.NotNull(controllerSettings, "controllerSettings"); var controllerFormatters = controllerSettings.Formatters; IList <ODataMediaTypeFormatter> odataFormatters = controllerFormatters.OfType <ODataMediaTypeFormatter>().ToList(); if (!odataFormatters.Any()) { foreach (var formatter in odataFormatters) { controllerFormatters.Remove(formatter); } } odataFormatters = ODataMediaTypeFormatters.Create( new DefaultRestierSerializerProvider(), new DefaultRestierDeserializerProvider()); controllerFormatters.InsertRange(0, odataFormatters); }
private static HttpServer makeHttpServer() { // Configure Web API for self-host. var config = new HttpConfiguration(); config.Routes.MapODataServiceBatchRoute( name: "DefaultOData", routeTemplate: "api/odata/{*wildcard}", defaults: new { controller = "ODService", action = "Get", wildcard = RouteParameter.Optional }); config.Routes.IgnoreRoute("ODataIgnore", "api/ODService/{*wildcard}"); config.Formatters.Clear(); config.Formatters.AddRange(ODataMediaTypeFormatters.Create()); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; return(new HttpServer(config)); }
public void ODataFormatter_CanReadDelta_WithAlias(string propertyName, string propertyNameAlias, string propertyJsonValue, object expectedValue) { // Arrange ODataConventionModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataConventionModelBuilder>(); builder.ModelAliasingEnabled = true; builder.EntityType <DeltaModelWithAlias>(); builder.EntitySet <DeltaModelWithAlias>("ignored"); IEdmModel model = builder.GetEdmModel(); IEnumerable <ODataMediaTypeFormatter> odataFormatters = ODataMediaTypeFormatters.Create(); Delta <DeltaModelWithAlias> delta; using (HttpRequestMessage request = new HttpRequestMessage { RequestUri = new Uri("http://localhost") }) { IEdmEntitySet entitySet = model.EntityContainer.EntitySets().Single(); HttpConfiguration config = new HttpConfiguration(); config.MapODataServiceRoute("default", "", model); request.ODataProperties().RouteName = "default"; request.SetConfiguration(config); request.ODataProperties().Model = model; request.ODataProperties().Path = new ODataPath(new EntitySetPathSegment(entitySet)); IEnumerable <MediaTypeFormatter> perRequestFormatters = odataFormatters.Select( (f) => f.GetPerRequestFormatterInstance(typeof(Delta <DeltaModelWithAlias>), request, null)); HttpContent content = new StringContent(String.Format("{{ '{0}' : {1} }}", propertyNameAlias, propertyJsonValue)); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json"); // Act delta = content.ReadAsAsync <Delta <DeltaModelWithAlias> >(perRequestFormatters).Result; } // Assert Assert.Equal(delta.GetChangedPropertyNames(), new[] { propertyName }); object value; Assert.True(delta.TryGetPropertyValue(propertyName, out value)); Assert.Equal(expectedValue, value); }
public static void Register(HttpConfiguration config) { // Web API routes config.MapHttpAttributeRoutes(); var builder = new ODataConventionModelBuilder(); builder.EntitySet <ApiPerson>("People"); builder.EntitySet <ApiContribution>("Contributions"); builder.EntitySet <ApiContributionFund>("Funds"); builder.EntitySet <ApiOrganization>("Organizations"); builder.EntitySet <ApiOrganizationMember>("OrganizationMembers"); config.MapODataServiceRoute( routeName: "ODataApiRoot", routePrefix: "api", model: builder.GetEdmModel()); var builderlookup = new ODataConventionModelBuilder(); builderlookup.EntitySet <ApiLookup>("Campuses"); builderlookup.EntitySet <ApiLookup>("Genders"); builderlookup.EntitySet <ApiLookup>("MaritalStatuses"); builderlookup.EntitySet <ApiLookup>("FamilyPositions"); builderlookup.EntitySet <ApiLookup>("ContributionTypes"); builderlookup.EntitySet <ApiLookup>("BundleHeaderTypes"); config.MapODataServiceRoute( routeName: "ODataApiLookupRoute", routePrefix: "api/lookup", model: builderlookup.GetEdmModel()); config.Filters.Add(new ApiAuthorizeAttribute()); config.MessageHandlers.Add(new ApiMessageLoggingHandler()); // fix for XML support (use Accept: application/xml) var formatters = ODataMediaTypeFormatters.Create(); config.Formatters.InsertRange(0, formatters); }
public async Task ODataFormatter_Can_Read_Delta(string propertyName, string propertyJsonValue, object expectedValue) { // Arrange ODataConventionModelBuilder builder = ODataModelBuilderMocks.GetModelBuilderMock <ODataConventionModelBuilder>(); builder.EntityType <DeltaModel>(); builder.EntitySet <DeltaModel>("ignored"); IEdmModel model = builder.GetEdmModel(); IEnumerable <ODataMediaTypeFormatter> odataFormatters = ODataMediaTypeFormatters.Create(); Delta <DeltaModel> delta; using (HttpRequestMessage request = new HttpRequestMessage { RequestUri = new Uri("http://localhost") }) { IEdmEntitySet entitySet = model.EntityContainer.EntitySets().Single(); HttpConfiguration config = new HttpConfiguration(); config.MapODataServiceRoute("default", "", model); request.SetConfiguration(config); request.EnableODataDependencyInjectionSupport("default"); request.ODataProperties().Path = new ODataPath(new EntitySetSegment(entitySet)); IEnumerable <MediaTypeFormatter> perRequestFormatters = odataFormatters.Select( (f) => f.GetPerRequestFormatterInstance(typeof(Delta <DeltaModel>), request, null)); HttpContent content = new StringContent(String.Format("{{ '{0}' : {1} }}", propertyName, propertyJsonValue)); content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/json;IEEE754Compatible=true"); // Act delta = await content.ReadAsAsync <Delta <DeltaModel> >(perRequestFormatters); } // Assert Assert.Equal(new[] { propertyName }, delta.GetChangedPropertyNames()); object value; Assert.True(delta.TryGetPropertyValue(propertyName, out value)); Assert.Equal(expectedValue, value); }
/// <summary> /// Enables OData support by adding an OData route and enabling OData controller and action selection, querying, and formatter support for OData. /// </summary> /// <param name="configuration">The server configuration.</param> /// <param name="model">The EDM model to use for the service.</param> /// <param name="routePrefix">The prefix to add to the OData route's path template.</param> public static void EnableOData(this HttpConfiguration configuration, IEdmModel model, string routePrefix) { if (configuration == null) { throw Error.ArgumentNull("configuration"); } if (model == null) { throw Error.ArgumentNull("model"); } // Querying configuration.SetEdmModel(model); configuration.EnableQuerySupport(); // Routing string routeTemplate = String.IsNullOrEmpty(routePrefix) ? ODataRouteConstants.ODataPathTemplate : routePrefix + "/" + ODataRouteConstants.ODataPathTemplate; IODataPathHandler pathHandler = configuration.GetODataPathHandler() ?? new DefaultODataPathHandler(model); IHttpRouteConstraint routeConstraint = new ODataPathRouteConstraint(pathHandler); configuration.Routes.MapHttpRoute(ODataRouteConstants.RouteName, routeTemplate, null, new HttpRouteValueDictionary() { { ODataRouteConstants.ConstraintName, routeConstraint } }); IEnumerable <IODataRoutingConvention> routingConventions = configuration.GetODataRoutingConventions(); IHttpControllerSelector controllerSelector = new ODataControllerSelector(routingConventions, configuration.Services.GetHttpControllerSelector()); IHttpActionSelector actionSelector = new ODataActionSelector(routingConventions, configuration.Services.GetActionSelector()); configuration.Services.Replace(typeof(IHttpControllerSelector), controllerSelector); configuration.Services.Replace(typeof(IHttpActionSelector), actionSelector); // Formatter configuration.Formatters.InsertRange(0, ODataMediaTypeFormatters.Create(model)); }
private IList <ODataMediaTypeFormatter> GetFormatters() { if (_formatters == null) { lock (_syncLock) { if (_formatters == null) { var serProvider = new CustomSerializerProvider(provider => new NuGetEntityTypeSerializer(provider)); var createdFormatters = ODataMediaTypeFormatters.Create(serProvider, new DefaultODataDeserializerProvider()); var jsonFormatters = createdFormatters.Where(x => x.SupportedMediaTypes.Any(y => y.MediaType.Contains("json"))); createdFormatters.RemoveAll(x => jsonFormatters.Contains(x)); var xmlFormatterIndex = createdFormatters.IndexOf(createdFormatters.Last(x => x.SupportedMediaTypes.Any(y => y.MediaType.Contains("xml")))); foreach (var formatter in jsonFormatters) { createdFormatters.Insert(xmlFormatterIndex++, formatter); } _formatters = createdFormatters; } } } return(_formatters); }
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(DefaultAuthenticationTypes.ApplicationCookie)); // Allows use ApplicationCookie authentication on WebApi config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType)); // Allows use Bearer authentication on WebApi // Return result in browser as JSON //config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html")); config.Formatters.Add(new BrowserJsonFormatter()); // Разрешить передавать циклические ссылки GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Objects; // Трактовать Unspecified дату как локальную (по умолчанию она трактуется как UTC) GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; // Не передавать названия свойств в JSON-объекте для свойств со значением null GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; // Web API routes // config.MapHttpAttributeRoutes(); config.MapHttpAttributeRoutes(new CustomDirectRouteProvider()); var odataFormatters = ODataMediaTypeFormatters.Create(new JsonODataSerializerProvider(), DefaultODataDeserializerProvider.Instance); // var odataFormatters = ODataMediaTypeFormatters.Create(new NullSerializerProvider(), DefaultODataDeserializerProvider.Instance); config.Formatters.InsertRange(0, odataFormatters); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); }
public static void Register(HttpConfiguration config) { config.Formatters.InsertRange(0, ODataMediaTypeFormatters.Create(new CustomSerializerProvider(), new DefaultODataDeserializerProvider())); config.MapODataServiceRoute("odata", "odata", GetEdmModel()); }
private static IEnumerable <ODataMediaTypeFormatter> CreateOutputFormatters(IEdmModel model) { var request = RequestFactory.CreateFromModel(model, "http://any"); return(ODataMediaTypeFormatters.Create().Select(f => f.GetPerRequestFormatterInstance(typeof(void), request, null) as ODataMediaTypeFormatter)); }
public override IList <ODataMediaTypeFormatter> CreateODataFormatters() { return(ODataMediaTypeFormatters.Create(new MediaEntitySerializerProvider(), new DefaultODataDeserializerProvider())); }
public static void Register(HttpConfiguration config) { int maxServerPageSize = Convert.ToInt32(WebConfigurationManager.AppSettings["maxServerPageSize"]); AzdaraInit(); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; // create a special dynamic controller selector TableControllerSelector selector = new TableControllerSelector(config); config.Services.Replace(typeof(IHttpControllerSelector), selector); //Use global configuration config.Count().Filter().OrderBy().Expand().Select().MaxTop(null); // enable query options for all properties config.AddODataQueryFilter(new EnableQueryAttribute() { PageSize = maxServerPageSize, AllowedQueryOptions = Microsoft.AspNet.OData.Query.AllowedQueryOptions.All, AllowedFunctions = Microsoft.AspNet.OData.Query.AllowedFunctions.All, AllowedArithmeticOperators = Microsoft.AspNet.OData.Query.AllowedArithmeticOperators.All, AllowedLogicalOperators = Microsoft.AspNet.OData.Query.AllowedLogicalOperators.All, //HandleNullPropagation = Microsoft.AspNet.OData.Query.HandleNullPropagationOption.True }); //строка для включения null значений в открытых типах, пример свойство в сущности public IDictionary<string, object> DynamicProperties { get; set; } config.Properties.AddOrUpdate("System.Web.OData.NullDynamicPropertyKey", val => true, (oldVal, newVal) => true); //Activate a key as Segment. Then request an entity with key as segment, the URL will be like ~/EntitySet/KeyValue or old ~/EntitySet(KeyValue) //Note : If entity type has composite key, then key as segment is not supported for this entity type config.SetUrlKeyDelimiter(Microsoft.OData.ODataUrlKeyDelimiter.Slash); config.SetTimeZoneInfo(TimeZoneInfo.Utc); // Конфигурация и службы веб-API IEdmModel EDMmodel = Metadata(); // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); // Create the default collection of built-in conventions. //var conventions = Microsoft.AspNet.OData.Routing.Conventions.ODataRoutingConventions.CreateDefault(); // Insert the custom convention at the start of the collection. //conventions.Insert(0, new NavigationIndexRoutingConvention()); config.MapODataServiceRoute( routeName: "ODataRoute", routePrefix: "odata", model: EDMmodel //,pathHandler: new Microsoft.AspNet.OData.Routing.DefaultODataPathHandler(), //routingConventions: conventions ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional } ); // below code allows endpoints to respond with either XML or JSON, depending on accept header preferences sent from client // (default in absence of accept header is JSON) //https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/json-and-xml-serialization var odataFormatters = ODataMediaTypeFormatters.Create(); config.Formatters.InsertRange(0, odataFormatters); }
/// <summary> /// Create the OData formatters. /// </summary> /// <param name="configuration">The configuration.</param> /// <returns>The OData formatters.</returns> public static IList <ODataMediaTypeFormatter> CreateOData(WebRouteConfiguration configuration) { return(ODataMediaTypeFormatters.Create()); }
public void Configuration(IAppBuilder appBuilder) { // Set up server configuration HttpConfiguration config = new HttpConfiguration(); // DscQRouteHandler config.MessageHandlers.Add(new DscQRouteHandler()); config.MapODataServiceRoute( routeName: "DscQuery", routePrefix: "{datasource}/{path}/odata", model: GetQueryEdmModel()); #region DI Container = new Container(rules => rules.WithoutThrowOnRegisteringDisposableTransient()).WithWebApi(config); Container.RegisterMany(new [] { GetType().Assembly }, (registrator, types, type) => { Type[] interfaces = type.GetInterfaces(); bool assignedFromDispatcher = interfaces.Any(i => i.IsAssignableTo(typeof(IJobDispatcher)) || i.IsAssignableTo(typeof(IQueryDispatcher))); if (assignedFromDispatcher || interfaces.Any(i => i.IsAssignableTo(typeof(IInterceptor)) || i.IsAssignableTo(typeof(IJob)) || i.IsAssignableTo(typeof(IQuery)) || (i.IsGenericType && i.GetGenericTypeDefinition() == typeof(IQueryHandler <,>)))) { // all dispatchers --> Reuse.InCurrentScope IReuse reuse = assignedFromDispatcher ? Reuse.InResolutionScope : Reuse.Transient; registrator.RegisterMany(types, type, reuse); // interceptors if (type.IsClass) { InterceptedObjectAttribute attr = (InterceptedObjectAttribute)type.GetCustomAttribute(typeof(InterceptedObjectAttribute)); if (attr != null) { Type serviceType = attr.ServiceInterfaceType ?? type.GetImplementedInterfaces().FirstOrDefault(); registrator.Intercept(serviceType, attr.InterceptorType); } } } }); Container.RegisterInstance((IOracleEnvironmentConfiguration)System.Configuration.ConfigurationManager.GetSection("oracleEnvironment")); Container.RegisterInstance(System.Configuration.ConfigurationManager.AppSettings["ProviderName"], serviceKey: "ProviderName"); Container.Register( reuse: Reuse.InResolutionScope, made: Made.Of(() => DbManagerFactory.CreateDbManager(Arg.Of <string>("ProviderName"), null), requestIgnored => string.Empty) ); // IDbManager initialiazation Container.RegisterInitializer <IDbManager>((m, r) => m.Log = Log.Logger.Debug); // cache manager Container.Register(reuse: Reuse.Singleton, made: Made.Of(() => CacheFactory.FromConfiguration <object>("webCache"))); Container.UseInstance(Container); #endregion // Startup Jobs IJobDispatcher dispatcher = Container.Resolve <IJobDispatcher>(IfUnresolved.ReturnDefault); dispatcher?.Dispatch <IStartupJob>(); config.Filters.Add(new GlobalExceptionFilter()); var odataFormatters = ODataMediaTypeFormatters.Create(new SkipNullValueODataSerializerProvider(), new DefaultODataDeserializerProvider()); config.Formatters.InsertRange(0, odataFormatters); appBuilder.UseWebApi(config); }
/// <summary> /// Creates the OData formatters. /// </summary> /// <returns>A collection of OData formatters.</returns> public virtual IList <ODataMediaTypeFormatter> CreateODataFormatters() { return(ODataMediaTypeFormatters.Create()); }
public void Initialize(HttpControllerSettings controllerSettings, HttpControllerDescriptor controllerDescriptor) { var odataFormatters = ODataMediaTypeFormatters.Create(new SerializerProvider(), new DerializerProvider()); controllerSettings.Formatters.InsertRange(0, odataFormatters); }