Example #1
0
        public override void Configure(Container container)
        {
            Plugins.Add(new SwaggerFeature());
            Plugins.Add(new RazorFormat());
            Plugins.Add(new RequestLogsFeature());

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

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(ContactsServices).Assembly);

            Plugins.Add(new AutoQueryFeature());

            container.Register<IDbConnectionFactory>(
                c => new OrmLiteConnectionFactory("~/db.sqlite".MapHostAbsolutePath(), SqliteDialect.Provider) {
                    ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                });

            using (var db = container.Resolve<IDbConnectionFactory>().Open())
            {
                db.DropAndCreateTable<Email>();
                db.DropAndCreateTable<Contact>();
                ContactsServices.AddCustomers(db);
            }

            UseDbEmailer(container);
            //UseSmtpEmailer(container); //Uncomment to use SMTP instead

            //ConfigureRabbitMqServer(container); //Uncomment to start accepting requests via Rabbit MQ
        }
Example #2
0
        public override void Configure(Container container)
        {
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AppHost).Assembly);

            container.RegisterAutoWired<BicyleRepository>();
        }
Example #3
0
        public override void Configure(Container container)
        {
            //ASP.NET MVC integration
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));

            SetConfig(CreateEndpointHostConfig());

            JsConfig.EmitCamelCaseNames = true;

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AppHost).Assembly);

            container.Register<ICacheClient>(new MemoryCacheClient());
            container.RegisterAutoWired<BicyleRepository>();

            Plugins.Add(new AuthFeature(
            () => new AuthUserSession(),
            new IAuthProvider[] {
                    new CredentialsAuthProvider()
                }));

            var userAuthRepository = new InMemoryAuthRepository();
            userAuthRepository.CreateUserAuth(new UserAuth { Email = "*****@*****.**", DisplayName= "Admin User"}, "admin");
            container.Register<IUserAuthRepository>(userAuthRepository);
        }
Example #4
0
        public override void Configure(Container container)
        {
            Plugins.Add(new SwaggerFeature());
            Plugins.Add(new RazorFormat());
            Plugins.Add(new RequestLogsFeature());

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(ContactsServices).Assembly);

            container.Register<IDbConnectionFactory>(
                c => new OrmLiteConnectionFactory("db.sqlite", SqliteDialect.Provider) {
                    ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                });

            using (var db = container.Resolve<IDbConnectionFactory>().Open())
            {
                db.DropAndCreateTable<Email>();
                db.DropAndCreateTable<Contact>();

                db.Insert(new Contact { Name = "Kurt Cobain", Email = "*****@*****.**", Age = 27 });
                db.Insert(new Contact { Name = "Jimi Hendrix", Email = "*****@*****.**", Age = 27 });
                db.Insert(new Contact { Name = "Michael Jackson", Email = "*****@*****.**", Age = 50 });
            }

            UseDbEmailer(container);
            //UseSmtpEmailer(container); //Uncomment to use SMTP instead

            //ConfigureRabbitMqServer(container); //Uncomment to start accepting requests via Rabbit MQ
        }
Example #5
0
        public override void Configure(Container container)
        {
            if (EnableRazor)
                Plugins.Add(new RazorFormat());

            Plugins.Add(new SwaggerFeature());
            Plugins.Add(new RequestInfoFeature());
            Plugins.Add(new RequestLogsFeature());
            Plugins.Add(new ServerEventsFeature());

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AutoValidationValidator).Assembly);


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

            using (var db = container.Resolve<IDbConnectionFactory>().OpenDbConnection())
            {
                db.DropAndCreateTable<Rockstar>(); //Create table if not exists
                db.Insert(Rockstar.SeedData); //Populate with seed data
            }

            SetConfig(new HostConfig {
                AdminAuthSecret = "secret",
                DebugMode = true,
            });
        }
Example #6
0
        public override void Configure(Container container)
        {
            SetConfig(new EndpointHostConfig {ServiceStackHandlerFactoryPath = "api"});

            //Set JSON web services to return idiomatic JSON camelCase properties
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;
            ServiceStack.Text.JsConfig.DateHandler = JsonDateHandler.ISO8601;

            Plugins.Add(new CorsFeature()); //Registers global CORS Headers

            RequestFilters.Add((httpReq, httpRes, requestDto) =>
                                   {
                                       //Handles Request and closes Responses after emitting global HTTP Headers
                                       if (httpReq.HttpMethod == "OPTIONS")
                                           httpRes.EndServiceStackRequest();
                                   });

            //Enable the validation feature
            Plugins.Add(new ValidationFeature());

            //This method scans the assembly for validators
            container.RegisterValidators(typeof(AppHost).Assembly);

            container.Register<ICacheClient>(new MemoryCacheClient());

            // register RavenDB dependencies
            ConfigureRavenDb(container);

            // register authentication framework
            ConfigureAuthentication(container);
        }
Example #7
0
        public override void Configure(Container container)
        {
            JsConfig.EmitCamelCaseNames = true;
            Plugins.Add(new RazorFormat());

            //Comment out 2 lines below to change to use local FileSystem instead of S3
            var s3Client = new AmazonS3Client(AwsConfig.AwsAccessKey, AwsConfig.AwsSecretKey, RegionEndpoint.USEast1);
            VirtualFiles = new S3VirtualPathProvider(s3Client, AwsConfig.S3BucketName, this);

            container.Register<IPocoDynamo>(c => new PocoDynamo(AwsConfig.CreateAmazonDynamoDb()));
            var db = container.Resolve<IPocoDynamo>();
            db.RegisterTable<Todos.Todo>();
            db.RegisterTable<EmailContacts.Email>();
            db.RegisterTable<EmailContacts.Contact>();
            db.InitSchema();

            //AWS Auth
            container.Register<ICacheClient>(new DynamoDbCacheClient(db, initSchema:true));
            container.Register<IAuthRepository>(new DynamoDbAuthRepository(db, initSchema:true));
            Plugins.Add(CreateAuthFeature());

            //EmailContacts
            ConfigureSqsMqServer(container);
            ConfigureEmailer(container);
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(EmailContacts.CreateContact).Assembly);
        }
Example #8
0
			public override void Configure (Container container)
			{
				container.Register<ICacheClient> (new MemoryCacheClient ());
				var appSettings = new AppSettings ();
				Plugins.Add (new AuthFeature (() => new WrenchAuthUserSession (),
				                              new[] { new GoogleOpenIdOAuthProvider (appSettings) }));
				Plugins.Add (new ValidationFeature ());
				container.RegisterValidators (typeof (WrenchAppHost).Assembly);
				Routes.AddFromAssembly (typeof (WrenchAppHost).Assembly);
			}
        public static void Register(Container container)
        {
            // add service validation
            container.RegisterValidators(ReuseScope.Container, typeof(ServiceStackServiceSolutionValidationAseembly).Assembly);

            container.RegisterAutoWiredAs<WidgetManager, IWidgetManager>();
            container.RegisterAutoWiredAs<InMemoryWidgetRepository, IWidgetRepository>();

            RegisterExternalAssemblies(container);
        }
Example #10
0
        public override void Configure(Container container)
        {
            SetConfig(CreateEndpointHostConfig());

            JsConfig.EmitCamelCaseNames = true;

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AppHost).Assembly);

            container.RegisterAutoWired<BicyleRepository>();
        }
Example #11
0
            public override void Configure(Container container)
            {
                container.Register<ICacheClient>(new MemoryCacheClient());

                ConfigureData(container);
                ConfigureAuth(container);
                ConfigureCors(container);

                Plugins.Add(new ValidationFeature());
                container.RegisterValidators(typeof(Global).Assembly);
            }
Example #12
0
 private static void RegisterDependencies(Container container)
 {
     //Register all your dependencies
     container.Register<ICacheClient>(new MemoryCacheClient());
     container.Register<IAuth>(new PasswordAuth());
     container.Register<IRepository>(AzureStorage.CreateSingleton(
         RoleEnvironment.GetConfigurationSettingValue("StorageConnectionString")
         ));
     container.RegisterAutoWired<XpmsAuthProvider>().ReusedWithin(ReuseScope.Hierarchy);
     container.RegisterProcesses<AbstractProcess>();
     container.RegisterValidators(typeof(SignupRequestValidator).Assembly);
     container.RegisterDataRecords<IRepoData>(typeof(AzureStorage).Assembly);
 }
Example #13
0
		public override void Configure (Container container)
		{
			LogManager.LogFactory = new NLogFactory ();
			this.RequestFilters.Add ((req, resp, requestDto) => {
				ILog log = LogManager.GetLogger (GetType ());
				log.Info (string.Format (
					"REQ {0}: {1} {2} {3} {4} {5}\n",
					DateTimeOffset.Now.Ticks, req.HttpMethod,
					req.OperationName, req.RemoteIp, req.RawUrl, req.UserAgent));
			});
			this.RequestFilters.Add ((req, resp, requestDto) => {
				ILog log = LogManager.GetLogger (GetType ());
				log.Info (string.Format (
					"RES {0}: {1} {2}\n",
					DateTimeOffset.Now.Ticks, resp.StatusCode, resp.ContentType));
			});

			JsConfig.DateHandler = JsonDateHandler.ISO8601;
            
			Plugins.Add (new AuthFeature (() => new AuthUserSession (),
				new IAuthProvider[] { new BasicAuthProvider () })
			);
			Plugins.Add (new RegistrationFeature ());
			Plugins.Add (new RequestLogsFeature ());
            
			container.RegisterAutoWiredAs<Scheduler, IScheduler> ();

			container.Register<ICacheClient> (new MemoryCacheClient ());            
			container.Register<IDbConnectionFactory> (new OrmLiteConnectionFactory 
				(@"Data Source=db.sqlite;Version=3;", SqliteOrmLiteDialectProvider.Instance));
            
			//Use OrmLite DB Connection to persist the UserAuth and AuthProvider info
			container.Register<IUserAuthRepository> (c => new OrmLiteAuthRepository (c.Resolve<IDbConnectionFactory> ()));

			Plugins.Add (new ValidationFeature ());
			container.RegisterValidators (typeof(AppHost).Assembly);
            
			var config = new EndpointHostConfig ();
            
			if (m_debugEnabled) {
				config.DebugMode = true; //Show StackTraces in service responses during development
				config.WriteErrorsToResponse = true;
				config.ReturnsInnerException = true;
			}

			container.AutoWire (this);
            
			SetConfig (config);
			CreateMissingTables (container);
		}
Example #14
0
        public override void Configure(Container container)
        {
            //ASP.NET MVC integration
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));

            SetConfig(CreateEndpointHostConfig());

            JsConfig.EmitCamelCaseNames = true;

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AppHost).Assembly);

            container.RegisterAutoWired<BicyleRepository>();
        }
        public void ConfigureAppHost(Container container, bool useTestDatabase = false)
        {
            JsConfig.EmitCamelCaseNames = true;
            JsConfig.DateHandler = JsonDateHandler.ISO8601;

            _appHost.Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof (AppHost).Assembly);

            container.Register<ICacheClient>(new MemoryCacheClient());

            _appHost.Plugins.Add(new AuthFeature(
                () => new AuthUserSession(),
                new IAuthProvider[]
                {
                    new CredentialsAuthProvider()
                }));

            if (useTestDatabase)
            {
                container.Register<IDbConnectionFactory>(
                    new OrmLiteConnectionFactory(
                        ":memory:",
                        false,
                        SqliteDialect.Provider));
            }
            else
            {
                container.Register<IDbConnectionFactory>(
                    new OrmLiteConnectionFactory(
                        ConfigurationManager.ConnectionStrings["SqlLiteConnection"].ConnectionString.MapHostAbsolutePath(),
                        SqliteDialect.Provider));
            }

            container.RegisterAutoWiredAs<BicyleRepository, IBicyleRepository>().ReusedWithin(ReuseScope.Request);

            container.Register<IUserAuthRepository>(c =>
                new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));

            var userAuthRepository = (OrmLiteAuthRepository) container.Resolve<IUserAuthRepository>();
            userAuthRepository.CreateMissingTables();
            if (userAuthRepository.GetUserAuthByUserName("*****@*****.**") == null)
            {
                userAuthRepository.CreateUserAuth(
                    new UserAuth {Email = "*****@*****.**", DisplayName = "Admin User"}, "admin");
            }

            InitializeDatabase(container);
        }
        public override void Configure(Container container)
        {
            // Auth
            Plugins.Add(new AuthFeature(() => new AuthUserSession(),
                new IAuthProvider[] { new BlueprintBasicAuth(), new BlueprintCredentialsAuth(), }));

            // Cache
            container.Register<ICacheClient>(new MemoryCacheClient());

            // Validators
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(UserValidators).Assembly, typeof(BlueprintValidators).Assembly);

            // Ioc
            IocBox.Kernel = new StandardKernel(new RealDomainModule(), new RealInfrastructureModule());
        }
Example #17
0
        public override void Configure(Container container)
        {
            this.container = container;

            this.RegisterDependencies(container);

            //Create ravendb indexes
            IndexCreation.CreateIndexes(typeof(AppHost).Assembly, container.Resolve<IDocumentStore>());

            //Register the request validators
            container.RegisterValidators(typeof(AppHost).Assembly);

            this.Plugins.Add(new ValidationFeature());

            this.GlobalRequestFilters.Add(this.AuthorizationFilter);
        }
Example #18
0
        public override void Configure(Container container)
        {
            if (Use != null)
                Use(container);

            if (EnableRazor)
                Plugins.Add(new RazorFormat());

            Plugins.Add(new SwaggerFeature());
            Plugins.Add(new RequestInfoFeature());
            Plugins.Add(new RequestLogsFeature());
            Plugins.Add(new ServerEventsFeature());

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AutoValidationValidator).Assembly);

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

            var dbFactory = container.Resolve<IDbConnectionFactory>();
            using (var db = dbFactory.OpenDbConnection())
            {
                db.DropAndCreateTable<Rockstar>(); //Create table if not exists
                db.Insert(Rockstar.SeedData); //Populate with seed data
            }

            SetConfig(new HostConfig {
                AdminAuthSecret = "secret",
                DebugMode = true,
            });

            if (EnableAuth)
            {
                Plugins.Add(new AuthFeature(() => new AuthUserSession(), 
                    new IAuthProvider[] {
                        new BasicAuthProvider(AppSettings),
                        new ApiKeyAuthProvider(AppSettings) { RequireSecureConnection = false },
                        new CredentialsAuthProvider(AppSettings),
                    })
                {
                    IncludeRegistrationService = true,
                });

                container.Resolve<IAuthRepository>().InitSchema();
            }
        }
Example #19
0
            public override void Configure(Container container)
            {
                SetConfig(new EndpointHostConfig()
                              {
                                  DefaultContentType = ContentType.Json,
                                  DebugMode = true,
                                  EnableFeatures = Feature.All,
                              });

                // Register privileges filter
                this.RequestFilters.Add((httpReq, httpResp, requestDto) =>
                                            {
                                            });

                // Register validators
                container.RegisterValidators(typeof (CreateUserValidator).Assembly);
            }
Example #20
0
        public override void Configure(Container container)
        {
            if (EnableRazor)
                Plugins.Add(new RazorFormat());

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AutoValidationValidator).Assembly);


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

            using (var db = container.Resolve<IDbConnectionFactory>().OpenDbConnection())
            {
                db.DropAndCreateTable<Rockstar>(); //Create table if not exists
                db.Insert(Rockstar.SeedData); //Populate with seed data
            }
        }
        public override void Configure(Container container)
        {
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(ValidateTestMqValidator).Assembly);

            var appSettings = new AppSettings();
            container.Register<IRedisClientsManager>(c => new PooledRedisClientManager(
                new[] { appSettings.GetString("Redis.Host") ?? "localhost" }));
            container.Register<IMessageService>(c => new RedisMqServer(c.Resolve<IRedisClientsManager>()));

            var mqServer = (RedisMqServer)container.Resolve<IMessageService>();
            mqServer.RegisterHandler<AnyTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler<PostTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler<ValidateTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler<ThrowGenericError>(ServiceController.ExecuteMessage);

            mqServer.Start();
        }
Example #22
0
        public override void Configure(Container container)
        {
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

            // Register RavenDB things
            container.Register(_documentStore);
            container.Register(c =>
            {
                var db = c.Resolve<IDocumentStore>();
                return db.OpenSession();
            }).ReusedWithin(ReuseScope.Request);

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(CreateWidgetValidator).Assembly);

            // todo: register all of your plugins here
            AuthConfig.Start(this, container);
        }
        public override void Configure(Container container)
        {
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(ValidateTestMqValidator).Assembly);

            var appSettings = new AppSettings();
            container.Register<IMessageService>(c =>
                new RabbitMqServer(appSettings.GetString("RabbitMq.Host") ?? "localhost"));
            container.Register(c =>
                ((RabbitMqServer) c.Resolve<IMessageService>()).ConnectionFactory);

            var mqServer = (RabbitMqServer)container.Resolve<IMessageService>();
            mqServer.RegisterHandler<AnyTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler<PostTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler<ValidateTestMq>(ServiceController.ExecuteMessage);
            mqServer.RegisterHandler<ThrowGenericError>(ServiceController.ExecuteMessage);

            mqServer.Start();
        }
Example #24
0
        /// <summary>
        /// Configure the container with the necessary routes for your ServiceStack application.
        /// </summary>
        /// <param name="container">The built-in IoC used with ServiceStack.</param>
        public override void Configure(Container container)
        {
            JsConfig.DateHandler = JsonDateHandler.ISO8601;

            // enable fluent validation
            Plugins.Add(new ValidationFeature());

            //This method scans the assembly for validators
            container.RegisterValidators(typeof(MembersValidator).Assembly);

            // Register our own custom validators
            container.Register<IEmailValidator>(new EmailValidator());

            //Using an in-memory cache
            container.Register<ICacheClient>(new MemoryCacheClient());

            AutomapperConfig.CreateMapping();

            DependencyResolverInitializer.Initialize();
        }
Example #25
0
        public override void Configure(Container container) {

            JsConfig.EmitCamelCaseNames = true;
            JsConfig.DateHandler = DateHandler.ISO8601;
            OrmLiteConfig.DialectProvider = SqlServerOrmLiteDialectProvider.Instance;
            SqlServerDialect.Provider.GetStringConverter().UseUnicode = true;
            SqlServerDialect.Provider.GetDateTimeConverter().DateStyle = DateTimeKind.Utc;

            Plugins.Add(new SessionFeature());
            Plugins.Add(new ValidationFeature());

            container.Register<IDbConnectionFactory>(c => new AppDbConnectionFactory());
            container.Register<IAppDbConnectionFactory>(c => new AppDbConnectionFactory());
            container.Register<ICredentialsDbConnectionFactory>(c => new CredentialsDbConnectionFactory());
            container.Register<ICacheClient>(new MemoryCacheClient { FlushOnDispose = false });
            container.RegisterApplicationDependencies();
            container.RegisterValidators(typeof(PlayerService).Assembly);
            ConfigureAuth(container);
            RegisterOrmLiteFilters(container);
            //CreateAuthDb(container);
        }
Example #26
0
        public override void Configure(Container container)
        {
            //ASP.NET MVC integration
            ControllerBuilder.Current.SetControllerFactory(new FunqControllerFactory(container));

            SetConfig(CreateEndpointHostConfig());

            JsConfig.EmitCamelCaseNames = true;

            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(AppHost).Assembly);

            container.Register<ICacheClient>(new MemoryCacheClient());

            Plugins.Add(new AuthFeature(
            () => new AuthUserSession(),
            new IAuthProvider[] {
                    new CredentialsAuthProvider()
                }));

            container.Register<IDbConnectionFactory>(
                new OrmLiteConnectionFactory(
                    ConfigurationManager.ConnectionStrings["SqlLiteConnection"].ConnectionString.MapHostAbsolutePath(),
                    SqliteDialect.Provider));

            container.RegisterAutoWired<BicyleRepository>().ReusedWithin(ReuseScope.Request);

            container.Register<IUserAuthRepository>(c =>
                new OrmLiteAuthRepository(c.Resolve<IDbConnectionFactory>()));

            var userAuthRepository = (OrmLiteAuthRepository)container.Resolve<IUserAuthRepository>();
            userAuthRepository.CreateMissingTables();
            if (userAuthRepository.GetUserAuthByUserName("*****@*****.**") == null)
            {
                userAuthRepository.CreateUserAuth(
                    new UserAuth { Email = "*****@*****.**", DisplayName = "Admin User" }, "admin");
            }

            InitializeDatabase(container);
        }
Example #27
0
        public override void Configure(Container container)
        {
            LogManager.LogFactory = new NLogFactory ();
            this.RequestFilters.Add ((req, resp, requestDto) => {
                ILog log = LogManager.GetLogger (GetType ());
                log.Info (string.Format ("REQ {0}: {1} {2} {3} {4} {5}",
                    DateTimeOffset.Now.Ticks, req.HttpMethod,
                    req.OperationName, req.RemoteIp, req.RawUrl, req.UserAgent));
            });
            this.ResponseFilters.Add ((req, resp, dto) => {
                ILog log = LogManager.GetLogger (GetType ());
                log.Info (string.Format ("RES {0}: {1} {2}", DateTimeOffset.Now.Ticks,
                    resp.StatusCode, resp.ContentType));
            });

            container.Register<IDbConnectionFactory> (
                new OrmLiteConnectionFactory (@"Data Source=db.sqlite;Version=3;",
                    SqliteOrmLiteDialectProvider.Instance) {
                    ConnectionFilter = x => new ProfiledDbConnection (x, Profiler.Current)
                });

            JsConfig.DateHandler = JsonDateHandler.ISO8601;

            Plugins.Add (new ValidationFeature ());
            container.RegisterValidators (typeof(AppHost).Assembly);

            var config = new EndpointHostConfig ();

            if (m_debugEnabled) {
                config.DebugMode = true; //Show StackTraces in service responses during development
                config.WriteErrorsToResponse = true;
                config.ReturnsInnerException = true;
            }

            SetConfig (config);

            SetUpDb (container);
        }
Example #28
0
        /// <summary>
        /// Application specific configuration
        /// This method should initialize any IoC resources utilized by your web service classes.
        /// </summary>
        /// <param name="container"></param>
        public override void Configure(Container container)
        {
            //Config examples
            //this.Plugins.Add(new PostmanFeature());
            //this.Plugins.Add(new CorsFeature());

            SetConfig(new HostConfig
            {
                DebugMode = AppSettings.Get("DebugMode", false),
                AddRedirectParamsToQueryString = true
            });

            this.Plugins.Add(new RazorFormat());
            Plugins.Add(new ValidationFeature());
            container.RegisterValidators(typeof(SignUpValidator).Assembly);

            container.Register<IDbConnectionFactory>(c =>
                new OrmLiteConnectionFactory("Data Source=c:\\mydb.db;Version=3;", SqliteDialect.Provider));

            using (var db = container.Resolve<IDbConnectionFactory>().Open())
            {
                db.CreateTableIfNotExists<User>();
            }
        }
Example #29
0
		public override void Configure (Container container)
		{
			JsConfig.DateHandler = JsonDateHandler.ISO8601;
			
			Plugins.Add (new AuthFeature (() => new AuthUserSession (),
			                              new IAuthProvider[] {new CredentialsAuthProvider ()})
			);
			Plugins.Add (new RegistrationFeature ());
			Plugins.Add (new RequestLogsFeature ());
			
			container.Register<ICacheClient> (new MemoryCacheClient ());
			
			container.Register<IDbConnectionFactory> (
				new OrmLiteConnectionFactory (@"Data Source=db.sqlite;Version=3;",
			                              SqliteOrmLiteDialectProvider.Instance)
				{
				ConnectionFilter = x => new ProfiledDbConnection (x, Profiler.Current)
			});
			
			//Use OrmLite DB Connection to persist the UserAuth and AuthProvider info
			container.Register<IUserAuthRepository> (c => new OrmLiteAuthRepository (c.Resolve<IDbConnectionFactory> ()));
			
			Plugins.Add (new ValidationFeature ());
			container.RegisterValidators (typeof(AppHost).Assembly);
			
			var config = new EndpointHostConfig ();
			
			if (m_debugEnabled) {
				config.DebugMode = true; //Show StackTraces in service responses during development
				config.WriteErrorsToResponse = true;
				config.ReturnsInnerException = true;
			}
			
			SetConfig (config);
			CreateMissingTables (container);
		}
Example #30
0
            public override void Configure(Container container)
            {
                IocShared.Configure(this);

                JsConfig.EmitCamelCaseNames = true;

                this.PreRequestFilters.Add((req, res) =>
                {
                    req.Items["_DataSetAtPreRequestFilters"] = true;
                });

                this.GlobalRequestFilters.Add((req, res, dto) =>
                {
                    req.Items["_DataSetAtRequestFilters"] = true;

                    var requestFilter = dto as RequestFilter;
                    if (requestFilter != null)
                    {
                        res.StatusCode = requestFilter.StatusCode;
                        if (!requestFilter.HeaderName.IsNullOrEmpty())
                        {
                            res.AddHeader(requestFilter.HeaderName, requestFilter.HeaderValue);
                        }
                        res.Close();
                    }

                    var secureRequests = dto as IRequiresSession;
                    if (secureRequests != null)
                    {
                        res.ReturnAuthRequired();
                    }
                });

                this.Container.Register<IDbConnectionFactory>(c =>
                    new OrmLiteConnectionFactory(
                        "~/App_Data/db.sqlite".MapHostAbsolutePath(),
                        SqliteDialect.Provider)
                    {
                        ConnectionFilter = x => new ProfiledDbConnection(x, Profiler.Current)
                    });

                this.Container.Register<ICacheClient>(new MemoryCacheClient());
                //this.Container.Register<ICacheClient>(new BasicRedisClientManager());

                ConfigureAuth(container);

                //this.Container.Register<ISessionFactory>(
                //    c => new SessionFactory(c.Resolve<ICacheClient>()));

                var dbFactory = this.Container.Resolve<IDbConnectionFactory>();

                using (var db = dbFactory.Open())
                    db.DropAndCreateTable<Movie>();

                ModelConfig<Movie>.Id(x => x.Title);
                Routes
                    .Add<Movies>("/custom-movies", "GET, OPTIONS")
                    .Add<Movies>("/custom-movies/genres/{Genre}")
                    .Add<Movie>("/custom-movies", "POST,PUT")
                    .Add<Movie>("/custom-movies/{Id}")
                    .Add<MqHostStats>("/mqstats");


                var resetMovies = this.Container.Resolve<ResetMoviesService>();
                resetMovies.Post(null);

                container.Register<IRedisClientsManager>(c => new RedisManagerPool());

                Plugins.Add(new ValidationFeature());
                Plugins.Add(new SessionFeature());
                Plugins.Add(new ProtoBufFormat());
                Plugins.Add(new RequestLogsFeature
                {
                    //RequestLogger = new RedisRequestLogger(container.Resolve<IRedisClientsManager>())
                    RequestLogger = new CsvRequestLogger(),
                });
                Plugins.Add(new SwaggerFeature
                {
                    //UseBootstrapTheme = true
                    OperationFilter = x => x.Consumes = x.Produces = new[] { MimeTypes.Json, MimeTypes.Xml }.ToList(),
                    RouteSummary =
                    {
                        { "/swaggerexamples", "Swagger Examples Summary" }
                    }
                });
                Plugins.Add(new PostmanFeature());
                Plugins.Add(new CorsFeature());
                Plugins.Add(new AutoQueryFeature { MaxLimit = 100 });
                Plugins.Add(new AdminFeature());

                container.RegisterValidators(typeof(CustomersValidator).Assembly);

                typeof(ResponseStatus)
                    .AddAttributes(new ServiceStack.DataAnnotations.DescriptionAttribute("This is the Response Status!"));

                typeof(ResponseStatus)
                   .GetProperty("Message")
                   .AddAttributes(new ServiceStack.DataAnnotations.DescriptionAttribute("A human friendly error message"));

                //var onlyEnableFeatures = Feature.All.Remove(Feature.Jsv | Feature.Soap);
                SetConfig(new HostConfig
                {
                    AdminAuthSecret = AuthTestsBase.AuthSecret,
                    ApiVersion = "0.2.0",
                    //EnableFeatures = onlyEnableFeatures,
                    DebugMode = true, //Show StackTraces for easier debugging
                });

                if (StartMqHost)
                {
                    var redisManager = new BasicRedisClientManager();
                    var mqHost = new RedisMqServer(redisManager);
                    mqHost.RegisterHandler<Reverse>(ExecuteMessage);
                    mqHost.Start();
                    this.Container.Register((IMessageService)mqHost);
                }
            }