CheckWeb.AppHost.Configure C# (CSharp) Method

Configure() public method

Configure the Web Application host.
public Configure ( Funq.Container container ) : void
container Funq.Container The container.
return void
        public override void Configure(Container container)
        {
            var nativeTypes = this.GetPlugin<NativeTypesFeature>();
            nativeTypes.MetadataTypesConfig.ExportTypes.Add(typeof(DayOfWeek));
            nativeTypes.MetadataTypesConfig.IgnoreTypes.Add(typeof(IgnoreInMetadataConfig));
            nativeTypes.InitializeCollectionsForType = NativeTypesFeature.DontInitializeAutoQueryCollections;
            //nativeTypes.MetadataTypesConfig.GlobalNamespace = "Check.ServiceInterface";

            // Change ServiceStack configuration
            this.SetConfig(new HostConfig
            {
                //UseHttpsLinks = true,
                AppendUtf8CharsetOnContentTypes = new HashSet<string> { MimeTypes.Html },
                //AllowJsConfig = false,

                // Set to return JSON if no request content type is defined
                // e.g. text/html or application/json
                //DefaultContentType = MimeTypes.Json,
#if !DEBUG
                // Show StackTraces in service responses during development
                DebugMode = true,
#endif
                // Disable SOAP endpoints
                //EnableFeatures = Feature.All.Remove(Feature.Soap)
                //EnableFeatures = Feature.All.Remove(Feature.Metadata)
            });

            container.Register<IServiceClient>(c =>
                new JsonServiceClient("http://localhost:55799/") {
                    CaptureSynchronizationContext = true,
                });

            Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });

            Plugins.Add(new AutoQueryDataFeature()
                .AddDataSource(ctx => ctx.MemorySource(GetRockstars())));

            Plugins.Add(new AdminFeature());

            Plugins.Add(new PostmanFeature());
            Plugins.Add(new CorsFeature());

            GlobalRequestFilters.Add((req, res, dto) =>
            {
                if (dto is AlwaysThrowsGlobalFilter)
                    throw new Exception(dto.GetType().Name);
            });

            Plugins.Add(new RequestLogsFeature {
                RequestLogger = new CsvRequestLogger(),
            });

            Plugins.Add(new DynamicallyRegisteredPlugin());

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

            using (var db = container.Resolve<IDbConnectionFactory>().Open())
            {
                db.DropAndCreateTable<Rockstar>();
                db.InsertAll(GetRockstars());
            }

            var dbFactory = (OrmLiteConnectionFactory)container.Resolve<IDbConnectionFactory>();

            dbFactory.RegisterConnection("SqlServer", 
                new OrmLiteConnectionFactory(
                    "Server=localhost;Database=test;User Id=test;Password=test;",
                    SqlServerDialect.Provider) {
                        ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                    });

            dbFactory.RegisterConnection("pgsql",
                new OrmLiteConnectionFactory(
                    "Server=localhost;Port=5432;User Id=test;Password=test;Database=test;Pooling=true;MinPoolSize=0;MaxPoolSize=200",
                    PostgreSqlDialect.Provider));

            using (var db = dbFactory.OpenDbConnection("pgsql"))
            {
                db.DropAndCreateTable<Rockstar>();
                db.DropAndCreateTable<PgRockstar>();

                db.Insert(new Rockstar { Id = 1, FirstName = "PostgreSQL", LastName = "Connection", Age = 1 });
                db.Insert(new PgRockstar { Id = 1, FirstName = "PostgreSQL", LastName = "Named Connection", Age = 1 });
            }

            //this.GlobalHtmlErrorHttpHandler = new RazorHandler("GlobalErrorHandler.cshtml");

            // Configure JSON serialization properties.
            this.ConfigureSerialization(container);

            // Configure ServiceStack database connections.
            this.ConfigureDataConnection(container);

            // Configure ServiceStack Authentication plugin.
            this.ConfigureAuth(container);

            // Configure ServiceStack Fluent Validation plugin.
            this.ConfigureValidation(container);

            // Configure ServiceStack Razor views.
            this.ConfigureView(container);
        }