/// <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()); JsConfig.EmitCamelCaseNames = true; SetConfig(new HostConfig { AppendUtf8CharsetOnContentTypes = new HashSet <string> { MimeTypes.Html }, AllowJsonpRequests = true, AllowFileExtensions = { "json", "cshtml" } } ); var conString = ConfigurationManager.ConnectionStrings["Portal"].ConnectionString; var conFactory = new OrmLiteConnectionFactory(conString, SqlServerDialect.Provider, true); container.Register <IDbConnectionFactory>(c => conFactory); var abc = new AutoQueryFeature(); //abc.ImplicitConventions.Add("%NotEqual", "{Field} != {Value}"); this.Plugins.Add(new AutoQueryFeature()); this.Plugins.Add(new RazorFormat()); }
public override void Configure(Container container) { container.Register <IDbConnectionFactory>( new OrmLiteConnectionFactory(":memory:", SqliteDialect.Provider)); //container.Register<IDbConnectionFactory>( // new OrmLiteConnectionFactory("Server={0};Database=test;User Id=test;Password=test;".Fmt(Environment.GetEnvironmentVariable("CI_HOST")), // SqlServerDialect.Provider)); //container.Register<IDbConnectionFactory>( // new OrmLiteConnectionFactory("Server=localhost;Database=test;UID=root;Password=test", // MySqlDialect.Provider)); //container.Register<IDbConnectionFactory>( // new OrmLiteConnectionFactory("Server=localhost;Port=5432;User Id=test;Password=test;Database=test;Pooling=true;MinPoolSize=0;MaxPoolSize=200", // PostgreSqlDialect.Provider)); using (var db = container.Resolve <IDbConnectionFactory>().Open()) { db.DropAndCreateTable <Rockstar>(); db.DropAndCreateTable <RockstarAlbum>(); db.DropAndCreateTable <RockstarGenre>(); db.DropAndCreateTable <Movie>(); db.InsertAll(SeedRockstars); db.InsertAll(SeedAlbums); db.InsertAll(SeedGenres); db.InsertAll(SeedMovies); } var autoQuery = new AutoQueryFeature { MaxLimit = 100, EnableRawSqlFilters = true, } .RegisterQueryFilter <QueryRockstarsFilter, Rockstar>((req, q, dto) => q.And(x => x.LastName.EndsWith("son")) ) .RegisterQueryFilter <QueryCustomRockstarsFilter, Rockstar>((req, q, dto) => q.And(x => x.LastName.EndsWith("son")) ) .RegisterQueryFilter <IFilterRockstars, Rockstar>((req, q, dto) => q.And(x => x.LastName.EndsWith("son")) ); Plugins.Add(autoQuery); }
public override void Configure(Container container) { container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory("Server=.;Database=Junkyard;User Id=sa;Password=Yours;", SqlServer2016Dialect.Provider)); var a = new AutoQueryFeature(); Plugins.Add(a); Plugins.Add(new PostmanFeature()); var dbFactory = container.Resolve <IDbConnectionFactory>(); using (var db = dbFactory.OpenDbConnection()) { var created = db.CreateTableIfNotExists <Person>(); db.CreateTableIfNotExists <Car>(); if (created) { for (int i = 0; i < 300; i++) { var person = new Person { FirstName = "First " + i, LastName = "Last " + i }; var cars = new List <Car>(); for (int j = 0; j < 3; j++) { cars.Add(new Car { Make = "BMW" + j }); } person.Cars.AddRange(cars); db.Save(person, references: true); } } } }
protected virtual AutoQueryFeature ConfigureAutoQueryFeature(AutoQueryFeature feature) => feature;
// public override async Task ProcessRequest(HttpContext context, Func<Task> next) // { // await context.Response.WriteAsync("Hello World!"); // } public override void Configure(Container container) { JsConfig.DateHandler = DateHandler.ISO8601; container.Register <IDbConnectionFactory>(c => new OrmLiteConnectionFactory(Path.Combine(_dataDir, "db.sqlite"), SqliteDialect.Provider)); var dbFactory = TryResolve <IDbConnectionFactory>(); // var hostConfig = new HostConfig // { // DebugMode = false, // enables some debugging features // EnableFeatures = Feature.All.Remove(Feature.Csv), // removes the CSV format // HandlerFactoryPath = "/api" // moves the ServiceStack api surface under a sub-route // }; // hostConfig.GlobalResponseHeaders["X-Powered-By"] = "FoxValley Power"; // SetConfig(hostConfig); // Routes.Add(typeof(PingRequest), "/pinger", "GET"); Plugins.Add(new PostmanFeature()); Plugins.Add(new CorsFeature()); Plugins.Add(new YamlFormat(true)); var authProviders = new IAuthProvider[] { new CredentialsAuthProvider(), new BasicAuthProvider(), new ApiKeyAuthProvider(), new JwtAuthProvider() { RequireSecureConnection = false, HashAlgorithm = "RS256", PrivateKeyXml = GetPrivateKeyXml() }, new DigestAuthProvider(this.AppSettings), new FacebookAuthProvider(this.AppSettings), new TwitterAuthProvider(this.AppSettings), new GithubAuthProvider(this.AppSettings) }; Plugins.Add(new AuthFeature(() => new AuthUserSession(), authProviders) { SaveUserNamesInLowerCase = true, }); Plugins.Add(new RegistrationFeature() { AtRestPath = "/register" }); // CACHING // container.Register<IRedisClientsManager>(c => new RedisManagerPool("localhost:6379")); if (container.TryResolve <IRedisClientsManager>() != null) // caching redis { container.Register(c => c.Resolve <IRedisClientsManager>().GetCacheClient()); } else if (dbFactory != null) // caching database { container.Register <ICacheClient>(new OrmLiteCacheClient() { DbFactory = dbFactory }); } else // caching in-memory { container.Register <ICacheClient>(new MemoryCacheClient()); } (TryResolve <ICacheClient>() as IRequiresSchema)?.InitSchema(); // AUTHENTICATION IAuthRepository authRepository; if (dbFactory != null) { authRepository = new OrmLiteAuthRepository(dbFactory); } else { authRepository = new InMemoryAuthRepository(); } Register <IAuthRepository>(authRepository); (TryResolve <IAuthRepository>() as IRequiresSchema)?.InitSchema(); var authRepo = TryResolve <IAuthRepository>(); if (authRepo != null) { var adminUser = authRepo.GetUserAuthByUserName("admin"); if (adminUser == null) { adminUser = authRepo.CreateUserAuth( new UserAuth { UserName = "******", DisplayName = "Administrator", Email = "*****@*****.**" }, "admin"); } var roles = authRepo.GetRoles(adminUser); if (!roles.Contains("Admin")) { authRepo.AssignRoles(adminUser, new [] { "Admin" }); } var guestUser = authRepo.GetUserAuthByUserName("guest"); if (guestUser == null) { guestUser = authRepo.CreateUserAuth( new UserAuth { UserName = "******", DisplayName = "Guest", Email = "*****@*****.**" }, "guest"); } } if (dbFactory != null) { using (var db = dbFactory.OpenDbConnection()) { db.CreateTableIfNotExists(typeof(Bookmark)); var bkFile = Path.Combine(_dataDir, "bookmarks.csv"); var bkFileOld = bkFile + ".old"; if (File.Exists(bkFileOld)) { File.Delete(bkFile); } if (File.Exists(bkFile)) { using (var stream = File.OpenRead(bkFile)) { var bookmarks = BookmarkUtils.ToBookmarks(stream); foreach (var bookmark in bookmarks) { bookmark.CreatedBy = "admin"; bookmark.CreatedById = 1; bookmark.CreatedOn = DateTime.UtcNow; bookmark.ModifiedBy = "admin"; bookmark.ModifiedById = 1; bookmark.ModifiedOn = DateTime.UtcNow; try { db.Insert(bookmark); } catch {} } } File.Move(bkFile, bkFile + ".old"); } } var autoQuery = new AutoQueryFeature { MaxLimit = 100 }; Plugins.Add(autoQuery); } Plugins.Add(new OpenApiFeature() { UseCamelCaseSchemaPropertyNames = true }); }