Exemplo n.º 1
0
        public override ODataSerializer GetODataPayloadSerializer(Type type, HttpRequestMessage request)
        {
            if (typeof(IEdmModel).IsAssignableFrom(type))
            {
                IServiceProvider oldProvider = request.Properties[RequestContainerKey] as IServiceProvider;

                IContainerBuilder builder = new DefaultContainerBuilder();
                builder.AddDefaultODataServices();
                builder.AddService <IEdmModel>(ServiceLifetime.Singleton, sp => CreateEdmModel());

                builder.AddService <IODataPathHandler, DefaultODataPathHandler>(ServiceLifetime.Singleton);

                builder.AddServicePrototype(new ODataMessageWriterSettings
                {
                    EnableMessageStreamDisposal = false,
                    MessageQuotas = new ODataMessageQuotas {
                        MaxReceivedMessageSize = Int64.MaxValue
                    },
                });

                IServiceProvider serviceProvider = builder.BuildContainer();

                request.Properties[RequestContainerKey] = serviceProvider;

                return(new MyMetadataSerializer(oldProvider));
            }

            return(base.GetODataPayloadSerializer(type, request));
        }
        public VersionedMetadataRoutingConventionTest()
        {
            var builder = new DefaultContainerBuilder();

            builder.AddDefaultODataServices();
            builder.AddService(Singleton, typeof(IEdmModel), sp => Test.Model);
            serviceProvider = builder.BuildContainer();
        }
Exemplo n.º 3
0
        private static IServiceProvider BuilderDefaultServiceProvider(Action <IContainerBuilder> setupAction)
        {
            IContainerBuilder odataContainerBuilder = new DefaultContainerBuilder();

            odataContainerBuilder.AddDefaultODataServices();

            odataContainerBuilder.AddService(ServiceLifetime.Singleton, sp => new DefaultQuerySettings());

            odataContainerBuilder.AddService(ServiceLifetime.Singleton, typeof(ODataUriResolver),
                                             sp => new UnqualifiedODataUriResolver {
                EnableCaseInsensitive = true
            });

            // Inject the default Web API OData services.
            odataContainerBuilder.AddDefaultWebApiServices();

            // Inject the customized services.
            setupAction?.Invoke(odataContainerBuilder);

            return(odataContainerBuilder.BuildContainer());
        }
        public static void AddDefaultSerializers(IServiceCollection services, IODataSerializerProvider serializerProvider)
        {
            // This is necessary to query the IOption<ODataOptions>
            services.AddOptions();

            // add the default OData lib services into service collection.
            IContainerBuilder builder = new DefaultContainerBuilder(services);

            builder.AddDefaultODataServices();

            services.TryAddEnumerable(ServiceDescriptor.Transient <IConfigureOptions <ODataOptions>, ODataOptionsSetup>());

            services.TryAdd(ServiceDescriptor.Singleton(s => new ODataEnumSerializer(serializerProvider)));
            services.TryAdd(ServiceDescriptor.Singleton(s => new ODataResourceSerializer(serializerProvider)));
            services.TryAdd(ServiceDescriptor.Singleton(s => new ODataResourceSetSerializer(serializerProvider)));

            services.AddSingleton <ODataPrimitiveSerializer>();
            services.AddSingleton <ODataEntityReferenceLinkSerializer>();
            services.AddSingleton <ODataEntityReferenceLinksSerializer>();
            services.AddSingleton <ODataErrorSerializer>();
            services.AddSingleton <ODataRawValueSerializer>();
        }