// Configure your AppHost with the necessary configuration and dependencies your App needs public override void Configure(Container container) { SetConfig(new HostConfig { DefaultRedirectPath = "/index.html", DebugMode = AppSettings.Get(nameof(HostConfig.DebugMode), false) }); JsConfig.IncludeNullValues = false; JsConfig.ExcludeTypeInfo = true; JsConfig.DateHandler = DateHandler.ISO8601; JsConfig.TextCase = TextCase.PascalCase; JsConfig.TimeSpanHandler = TimeSpanHandler.StandardFormat; #region Database var connString = AppSettings.Get("dbConnectionString", ""); if (connString == "%%CONN_STR%%") { connString = AppSettings.Get("dbConnectionStringDev", ""); } var dbFactory = new OrmLiteConnectionFactory(connString, SqlServer2008Dialect.Provider); container.Register <IDbConnectionFactory>(dbFactory); OrmLiteConfig.StringFilter = s => s.Trim(); #endregion #region Plugins Plugins.Add(new CorsFeature( allowedHeaders: "Content-Type, Allow, Authorization")); Plugins.Add(new OpenApiFeature() { ApiDeclarationFilter = declaration => { declaration.Info.Title = "Badges Molex Net Core"; //declaration.Info.Contact = new ServiceStack.Api.OpenApi.Specification.OpenApiContact() //{ // Email = "*****@*****.**", // Name = "Alfredo Pacheco" //}; declaration.Info.Description = ""; }, OperationFilter = (verb, op) => { switch (verb) { case "POST": op.Parameters.RemoveAll(p => p.Name == "Id"); op.Parameters.RemoveAll(p => p.Name == "RowVersion"); break; default: break; } op.Parameters.RemoveAll(p => p.Name == "EntityName"); op.Parameters.RemoveAll(p => p.Name == "EF_State"); } }); Plugins.Add(new AutoQueryFeature { //MaxLimit = 100 }); Plugins.Add(new RequestLogsFeature()); Plugins.Add(new AdminFeature()); // var rollbarSettings = AppSettings.Get<RollbarSettings>("RollbarPluginSettings"); // Plugins.Add(new RollbarLoggerPlugin // { // ApiKey = rollbarSettings.ApiKey, // Enabled = rollbarSettings.Enabled, // EnableErrorTracking = rollbarSettings.EnableErrorTracking, // EnableRequestBodyTracking = rollbarSettings.EnableRequestBodyTracking, // EnableResponseTracking = rollbarSettings.EnableResponseTracking, // EnableSessionTracking = rollbarSettings.EnableSessionTracking, // Environment = rollbarSettings.Environment, // // HideRequestBodyForRequestDtoTypes = new List<Type>(), // // ExcludeRequestDtoTypes = new List<Type> // // { // // // Might have to exclude the Swagger requests to get the two to play nicely // // typeof(RollbarLogConfigRequest), // // typeof(SwaggerResource), // // typeof(SwaggerApiDeclaration) // // }, // RequiredRoles = rollbarSettings.RequiredRoles, // SkipLogging = IsRequestSkippedDuringRequestLogging // }); #endregion #region Auth var authProviders = new List <IAuthProvider> { new JwtAuthProvider(AppSettings) { RequireSecureConnection = false, AllowInQueryString = true }, new CredentialsAuthProvider() }; var authFeature = new AuthFeature(SessionFactory, authProviders.ToArray()); Plugins.Add(authFeature); //var authRepo = new OrmLiteAuthRepository(dbFactory); //container.Register<IUserAuthRepository>(authRepo); //authRepo.InitSchema(); //Plugins.Add(new RegistrationFeature()); //var admin = authRepo.GetUserAuthByUserName("admin"); //if (admin == null) // authRepo.CreateUserAuth(new UserAuth // { // UserName = "******", // Roles = new List<string> { RoleNames.Admin } // }, "admin"); #endregion //TODO: //Cache. //Logging. //Batched requests. //Profiler. //Versioning. //stripe.com #region Cache //container.Register<ICacheClient>(new MemoryCacheClient()); #endregion #region App //container.Register(c => dbFactory.Open()); //container.Register(c => c.Resolve<IDbConnectionFactory>().OpenDbConnection()).ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <RevisionLogic>().ReusedWithin(ReuseScope.Request); MailgunService.AppSettings = AppSettings; container.Register <IEmailService>(i => new MailgunService()).ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <CatalogLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <CatalogDefinitionLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <FieldLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <CatalogFieldValueLogic>().ReusedWithin(ReuseScope.Request); //This App: ///start:generated:di<<< container.RegisterAutoWired <ActivityLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <ApprovalLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <BadgeLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <EmailLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <AdvancedSortLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <ApplicationTaskLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <FilterDataLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <SortDataLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <TokenLogic>().ReusedWithin(ReuseScope.Request); ///end:generated:di<<< #endregion #region Seed Data Sower.Seed(dbFactory); #endregion }
// Configure your AppHost with the necessary configuration and dependencies your App needs public override void Configure(Container container) { #region Logger LogManager.LogFactory = new NLogFactory(); Plugins.Add(new SharpPagesFeature { MetadataDebugAdminRole = RoleNames.Admin }); ILog Log = LogManager.GetLogger("MyApp"); #endregion SetConfig(new HostConfig { DefaultRedirectPath = "/index.html", DebugMode = AppSettings.Get(nameof(HostConfig.DebugMode), false) }); JsConfig.IncludeNullValues = false; JsConfig.ExcludeTypeInfo = true; JsConfig.DateHandler = DateHandler.ISO8601; JsConfig.TextCase = TextCase.PascalCase; JsConfig.TimeSpanHandler = TimeSpanHandler.StandardFormat; #region Database var connString = AppSettings.Get("dbConnectionString", ""); if (connString == "%%CONN_STR%%") { connString = AppSettings.Get("dbConnectionStringDev", ""); } IOrmLiteDialectProvider dbProvider; switch (AppSettings.Get("dbProvider", "")) { case "postgresql": dbProvider = PostgreSqlDialect.Provider; break; case "sqlserver2008": dbProvider = SqlServerDialect.Provider; break; case "sqlserver2012": dbProvider = SqlServer2012Dialect.Provider; break; case "sqlserver2014": dbProvider = SqlServer2014Dialect.Provider; break; case "sqlserver2016": dbProvider = SqlServer2016Dialect.Provider; break; case "sqlserver2017": dbProvider = SqlServer2017Dialect.Provider; break; default: dbProvider = SqlServerDialect.Provider; break; } var dbFactory = new OrmLiteConnectionFactory(connString, dbProvider); container.Register <IDbConnectionFactory>(dbFactory); // OrmLiteConfig.StringFilter = s => s.Trim(); OrmLiteConfig.DialectProvider.StringSerializer = new JsonStringSerializer(); MyNamingStrategy.AppSettings = AppSettings; dbProvider.NamingStrategy = new MyNamingStrategy(); #endregion #region Plugins Plugins.Add(new CorsFeature( allowedHeaders: "Content-Type, Allow, Authorization")); Plugins.Add(new OpenApiFeature() { ApiDeclarationFilter = declaration => { declaration.Info.Title = "MDC"; // declaration.Info.Contact = new ServiceStack.Api.OpenApi.Specification.OpenApiContact() // { // Email = "*****@*****.**", // Name = "Alfredo Pacheco" // }; declaration.Info.Description = ""; }, OperationFilter = (verb, op) => { switch (verb) { case "POST": op.Parameters.RemoveAll(p => p.Name == "Id"); op.Parameters.RemoveAll(p => p.Name == "RowVersion"); break; default: break; } op.Parameters.RemoveAll(p => p.Name == "EntityName"); op.Parameters.RemoveAll(p => p.Name == "EF_State"); } }); Plugins.Add(new AutoQueryFeature { // MaxLimit = 100 }); Plugins.Add(new RequestLogsFeature()); Plugins.Add(new AdminFeature()); Plugins.Add(new ServerEventsFeature()); // var rollbarSettings = AppSettings.Get<RollbarSettings>("RollbarPluginSettings"); // Plugins.Add(new RollbarLoggerPlugin // { // ApiKey = rollbarSettings.ApiKey, // Enabled = rollbarSettings.Enabled, // EnableErrorTracking = rollbarSettings.EnableErrorTracking, // EnableRequestBodyTracking = rollbarSettings.EnableRequestBodyTracking, // EnableResponseTracking = rollbarSettings.EnableResponseTracking, // EnableSessionTracking = rollbarSettings.EnableSessionTracking, // Environment = rollbarSettings.Environment, // // HideRequestBodyForRequestDtoTypes = new List<Type>(), // // ExcludeRequestDtoTypes = new List<Type> // // { // // // Might have to exclude the Swagger requests to get the two to play nicely // // typeof(RollbarLogConfigRequest), // // typeof(SwaggerResource), // // typeof(SwaggerApiDeclaration) // // }, // RequiredRoles = rollbarSettings.RequiredRoles, // SkipLogging = IsRequestSkippedDuringRequestLogging // }); #endregion #region Auth var authProviders = new List <IAuthProvider> { new JwtAuthProvider(AppSettings) { RequireSecureConnection = false, AllowInQueryString = true }, new CredentialsAuthProvider(), new ApiKeyAuthProvider() { RequireSecureConnection = false, SessionCacheDuration = TimeSpan.FromMinutes(30) } }; var authFeature = new AuthFeature(SessionFactory, authProviders.ToArray()); Plugins.Add(authFeature); var authRepo = new OrmLiteAuthRepository <Account, UserAuthDetails>(dbFactory); container.Register <IAuthRepository>(authRepo); authRepo.InitSchema(); authRepo.InitApiKeySchema(); Plugins.Add(new RegistrationFeature()); var admin = authRepo.GetUserAuthByUserName("admin"); if (admin == null) { authRepo.CreateUserAuth(new Account { UserName = "******", Roles = new List <string> { RoleNames.Admin } }, "admin"); } #endregion // TODO: // Cache. // Logging. // Batched requests. // Profiler. // Versioning. // stripe.com #region Cache // container.Register<ICacheClient>(new MemoryCacheClient()); #endregion #region App AttachmentsIO.AppSettings = AppSettings; // container.Register(c => dbFactory.Open()); // container.Register(c => c.Resolve<IDbConnectionFactory>().OpenDbConnection()).ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <RevisionLogic>().ReusedWithin(ReuseScope.Request); EmailService.AppSettings = AppSettings; container.Register <IEmailService>(i => new EmailService()).ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <CatalogLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <CatalogDefinitionLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <FieldLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <CatalogFieldValueLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <AccountLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <TokenLogic>().ReusedWithin(ReuseScope.Request); // This App: ///start:generated:di<<< container.RegisterAutoWired <ApproverLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <AttachmentFileCommentLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <MDCLogic>().ReusedWithin(ReuseScope.Request); container.RegisterAutoWired <MdcAttachmentFileLogic>().ReusedWithin(ReuseScope.Request); ///end:generated:di<<< #endregion #region Seed Data Sower.Seed(dbFactory); #endregion Log.Info("================= Application Started ================="); } // Configure