Esempio n. 1
0
        public override void Configure(Container container)
        {
            //Signal advanced web browsers what HTTP Methods you accept
            base.SetConfig(new HostConfig {
                GlobalResponseHeaders =
                {
                    { "Access-Control-Allow-Origin",  "*"                               },
                    { "Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS" },
                },
                WsdlServiceNamespace  = "http://www.servicestack.net/types",
                DebugMode             = true,
                PreferredContentTypes = { MimeTypes.ProtoBuf },
            });

            this.RegisterRequestBinder <CustomRequestBinder>(
                httpReq => new CustomRequestBinder {
                IsFromBinder = true
            });

            Routes
            .Add <Movies>("/custom-movies", "GET")
            .Add <Movies>("/custom-movies/genres/{Genre}")
            .Add <Movie>("/custom-movies", "POST,PUT")
            .Add <Movie>("/custom-movies/{Id}")
            .Add <GetFactorial>("/fact/{ForNumber}")
            .Add <MoviesZip>("/all-movies.zip")
            .Add <GetHttpResult>("/gethttpresult")
            ;

            container.Register <IAppSettings>(new AppSettings());

            //var appSettings = container.Resolve<IResourceManager>();

            container.Register(c => new ExampleConfig(c.Resolve <IAppSettings>()));
            //var appConfig = container.Resolve<ExampleConfig>();

            container.Register <IDbConnectionFactory>(c =>
                                                      new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider));

            var resetMovies = container.Resolve <ResetMoviesService>();

            resetMovies.Post(null);

            //var movies = container.Resolve<IDbConnectionFactory>().Exec(x => x.Select<Movie>());
            //Console.WriteLine(movies.Dump());

            if (ConfigureFilter != null)
            {
                ConfigureFilter(container);
            }

            Plugins.Add(new ProtoBufFormat());
            Plugins.Add(new RequestInfoFeature());

            ContentTypes.Register("application/x-custom+json",
                                  (req, dto, stream) => stream.Write("{\"custom\":\"json\"}"),
                                  (type, stream) => type.CreateInstance());
        }
Esempio n. 2
0
        public override void Configure(Container container)
        {
            const string contentType = "application/csp-report";

            ContentTypes.Register(contentType, (req, o, stream) => JsonSerializer.SerializeToStream(o.GetType(), stream),
                                  JsonSerializer.DeserializeFromStream);

            Log.Logger = CreateLogger();
        }
Esempio n. 3
0
        public override void Configure(Container container)
        {
            Plugins.Add(new CsvFormat()); //required to allow .csv

            ContentTypes.Register(MimeTypes.PlainText,
                                  (req, o, stream) => JsonSerializer.SerializeToStream(o.GetType(), stream),
                                  JsonSerializer.DeserializeFromStream);

            PreRequestFilters.Add((req, res) => {
                if (req.ContentType.MatchesContentType(MimeTypes.PlainText))
                {
                    req.ResponseContentType = MimeTypes.Json;
                }
            });
        }
Esempio n. 4
0

        
Esempio n. 5
0
        public override void Configure(Container container)
        {
            SetConfig(new HostConfig
            {
                AllowRouteContentTypeExtensions = true
            });

            Plugins.Add(new CsvFormat()); //required to allow .csv

            Plugins.RemoveAll(x => x is MarkdownFormat);

            ContentTypes.Register(MimeTypes.PlainText,
                                  (req, o, stream) => JsonSerializer.SerializeToStream(o.GetType(), stream),
                                  JsonSerializer.DeserializeFromStream);

            PreRequestFilters.Add((req, res) => {
                if (req.ContentType.MatchesContentType(MimeTypes.PlainText))
                {
                    req.ResponseContentType = MimeTypes.Json;
                }
            });
        }