// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <ApplicationContext>(x => { x.UseMySql(Configuration.GetConnectionString("Database"), ServerVersion.FromString("8.0.22-mysql"), opt => { opt.CommandTimeout(3); }); }); services.AddCap(x => { x.UseDashboard(); x.UseEntityFramework <ApplicationContext>(); x.UseRabbitMQ(r => { r.HostName = "localhost"; r.Port = 5672; r.UserName = "******"; r.Password = "******"; }); x.FailedRetryCount = 3; }); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "Subscriber", Version = "v1" }); }); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { optionsBuilder.UseMySql(_connectionString, ServerVersion.FromString("5.7.32-mysql")); } }
public static void ConfigureMySqlContext(this IServiceCollection services, IConfiguration config) { var connectionString = config.GetConnectionString("GameDb"); services.AddDbContext <GameDbContext>( builder => builder.UseMySql(connectionString, ServerVersion.FromString("5.7"))); }
public void Bug_exists_in_MySql57_or_higher_parameter() { // Parameters are an issue as well, because the get inlined by MySqlConnector and // just become constant values as well. using var command = Connection.CreateCommand(); command.CommandText = @" SELECT `od1`.`Constant`, `od1`.`OrderID` FROM `Orders` AS `o` LEFT JOIN ( SELECT @p0 AS `Constant`, `od`.`OrderID` FROM `Order Details` AS `od` ) AS `od1` ON `o`.`OrderID` = `od1`.`OrderID` ORDER BY `od1`.`OrderID`;"; command.Parameters.AddWithValue("@p0", "MyParameterValue"); using var reader = command.ExecuteReader(); while (reader.Read()) { var constant = reader["Constant"]; var expected = ServerVersion.FromString(Connection.ServerVersion).Supports.MySqlBug96947Workaround ? (object)DBNull.Value : "MyParameterValue"; Assert.Equal(expected, constant); } }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddSignalR(); services.AddControllersWithViews(); services.AddRazorPages(); services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme) .AddCookie(); // For dependency injection // DbContext services.AddDbContext <SmartProctorDbContext>( db => db.UseMySql("server=localhost;user id=root;password=Mayuri;database=smartproctor;TreatTinyAsBoolean=True", ServerVersion.FromString("8.0.23-mysql"))); // Repositories services.AddTransient <IUserRepository, UserRepository>(); services.AddTransient <IEventRepository, EventRepository>(); services.AddTransient <IExamRepository, ExamRepository>(); services.AddTransient <IExamUserRepository, ExamUserRepository>(); services.AddTransient <IQuestionRepository, QuestionRepository>(); services.AddTransient <IAnswerRepository, AnswerRepository>(); // Services services.AddTransient <IUserServices, UserServices>(); services.AddTransient <IExamServices, ExamServices>(); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { LoadConfigs(); var mapConfig = new MapperConfiguration(x => { x.AddProfile(new MappingProfile()); }); IMapper mapper = mapConfig.CreateMapper(); services.AddSingleton(mapper); services.AddDbContextPool <ValourDB>(options => { options.UseMySql(ValourDB.ConnectionString, ServerVersion.FromString("8.0.20-mysql"), options => options.EnableRetryOnFailure().CharSet(CharSet.Utf8Mb4)); }); // This probably needs to be customized further but the documentation changed services.AddAuthentication().AddCookie(CookieAuthenticationDefaults.AuthenticationScheme); // Adds user manager to dependency injection services.AddScoped <UserManager>(); services.AddSignalR(); services.AddControllersWithViews(); services.AddRazorPages(); }
public virtual void Insert_and_read_Guid_value(MySqlGuidFormat guidFormat, string sqlEquivalent, string supportedServerVersion) { if (supportedServerVersion != null && !AppConfig.ServerVersion.Supports.Version(ServerVersion.FromString(supportedServerVersion))) { return; } using var context = CreateContext(guidFormat); context.Database.EnsureDeleted(); context.Database.EnsureCreated(); context.SimpleGuidEntities.Add(new SimpleGuidEntity { GuidValue = new Guid("850368D8-93EA-4023-ACC7-6FA6E4C3B27F") }); context.SaveChanges(); var result = context.SimpleGuidEntities .Where(e => e.GuidValue == new Guid("850368D8-93EA-4023-ACC7-6FA6E4C3B27F")) .ToList(); var sqlResult = context.SimpleGuidEntities .FromSqlRaw(@"select * from `SimpleGuidEntities` where `GuidValue` = " + string.Format(sqlEquivalent, new Guid("850368D8-93EA-4023-ACC7-6FA6E4C3B27F"))) .ToList(); Assert.Single(result); Assert.Equal(new Guid("850368D8-93EA-4023-ACC7-6FA6E4C3B27F"), result[0].GuidValue); Assert.Single(sqlResult); }
// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddPolicy("AllowAll", builder => { builder .AllowAnyMethod() .AllowAnyHeader() .SetIsOriginAllowed(_ => true) .AllowCredentials() .WithOrigins( "https://www.valour.gg", "http://www.valour.gg", "https://valour.gg", "http://valour.gg", "https://api.valour.gg", "http://api.valour.gg", "http://localhost:3000", "https://localhost:3000", "http://localhost:3001", "https://localhost:3001"); }); }); LoadConfigs(); services.AddSignalR(); var mapConfig = new MapperConfiguration(x => { x.AddProfile(new MappingProfile()); }); IMapper mapper = mapConfig.CreateMapper(); services.AddSingleton(mapper); MappingManager.Mapper = mapper; services.AddDbContextPool <ValourDB>(options => { options.UseMySql(ValourDB.ConnectionString, ServerVersion.FromString("8.0.20-mysql"), options => options.EnableRetryOnFailure().CharSet(CharSet.Utf8Mb4)); }); // This probably needs to be customized further but the documentation changed services.AddAuthentication().AddCookie(CookieAuthenticationDefaults.AuthenticationScheme); // Adds user manager to dependency injection services.AddScoped <UserManager>(); IdManager idManager = new IdManager(); services.AddSingleton <IdManager>(idManager); services.AddControllersWithViews(); services.AddRazorPages(); services.AddHostedService <MessageCacheWorker>(); services.AddHostedService <PlanetMessageWorker>(); services.AddHostedService <StatWorker>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(); services.AddDbContext <StoreContext>(opt => opt.UseMySql( Configuration.GetConnectionString("StoreContext"), ServerVersion.FromString(Configuration.GetValue <string>("mariadb-version")) )); }
public void TestValidVersion(string input, ServerType serverType, string actualVersion, bool supportsRenameIndex) { var serverVersion = ServerVersion.FromString(input); Assert.Equal(serverVersion.Type, serverType); Assert.Equal(serverVersion.Version, new Version(actualVersion)); Assert.Equal(serverVersion.Supports.RenameIndex, supportsRenameIndex); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddAuthentication(ApiTokenDefaults.AuthenticationScheme) .AddApiToken(op => op.UseCache = false) // .AddRedisCache(op => op.ConnectionString = "192.168.3.57:6379") .AddProfileService <MyApiTokenProfileService>() .AddTokenStore <MyApiTokenStore>() .AddCleanService(); // .AddRedisCache(op=>op.ConnectionString="xxx"); services.AddControllers().AddNewtonsoftJson(op => { op.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Local; op.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm"; op.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); }); //Swagger services.AddSwaggerGen(op => { op.UseInlineDefinitionsForEnums(); op.SwaggerDoc("v1", new OpenApiInfo { Title = typeof(Startup).Namespace, Version = "v1" }); op.DocInclusionPredicate((docName, description) => true); op.AddSecurityDefinition("ApiToken", new OpenApiSecurityScheme { Description = "Input Bearer {token}\"", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "ApiToken" }); op.AddSecurityRequirement(new OpenApiSecurityRequirement { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "ApiToken" } }, new string[] { } } }); }); services.AddSwaggerGenNewtonsoftSupport(); services.AddDbContext <ApiTokenDbContext>(options => options.UseMySql( Configuration.GetConnectionString("DefaultConnection"), ServerVersion.FromString("5.7-mysql"), mySqlOptions => mySqlOptions .CharSetBehavior(CharSetBehavior.NeverAppend))); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { if (!optionsBuilder.IsConfigured) { #warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https: //go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. optionsBuilder.UseMySql( connectionString: "server=localhost;database=MovieCatalogCodeFirst;uid=root;pwd=password", serverVersion: ServerVersion.FromString("10.4.13-mariadb")); } }
public MyAppMigrationsDbContext CreateDbContext(string[] args) { MyAppEfCoreEntityExtensionMappings.Configure(); var configuration = BuildConfiguration(); var builder = new DbContextOptionsBuilder <MyAppMigrationsDbContext>() .UseMySql(configuration.GetConnectionString("Default"), ServerVersion.FromString("8.0.21-mysql")); return(new MyAppMigrationsDbContext(builder.Options)); }
public DogStoreMigrationsDbContext CreateDbContext(string[] args) { var configuration = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: false).Build(); var builder = new DbContextOptionsBuilder <DogStoreMigrationsDbContext>() .UseMySql(configuration.GetConnectionString("DogStore"), ServerVersion.FromString("3.1")); return(new DogStoreMigrationsDbContext(builder.Options)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext <CustomerRelationsDatabaseContext>(options => options.UseMySql( Configuration["DBInfo:ConnectionString"], ServerVersion.FromString("8.0.23-mysql"))); // to access session directly from view, corresponds with: @using Microsoft.AspNetCore.Http in Views/_ViewImports.cshtml services.AddHttpContextAccessor(); services.AddSession(); services.AddMvc(options => options.EnableEndpointRouting = false); }
public WarehouseContext CreateDbContext(string[] args) { var properties = new ConfigurationBuilder().AddJsonFile("appsettings.json").Build(); var optionsbuilder = new DbContextOptionsBuilder <WarehouseContext>(); optionsbuilder .UseLoggerFactory(LoggerFactory.Create(builder => builder.AddConsole())) .UseMySql(properties["ConnectionStrings:DefaultConnection"], ServerVersion.FromString("8.0.23"), null); return(new WarehouseContext(optionsbuilder.Options)); }
private void ConfigureMySQL(IServiceCollection services) { _mySqlConnection = GetConnection(); services.Configure <AbpDbContextOptions>(options => { options.Configure(context => { context.DbContextOptions.UseMySql(_mySqlConnection, ServerVersion.FromString("8.0")); }); }); }
public ProfilerMariaDbContext CreateDbContext(string[] args) { var optionsBuilder = new DbContextOptionsBuilder <ProfilerMariaDbContext>(); #if NETCOREAPP3_1 optionsBuilder.UseMySql("----"); #elif NET5_0_OR_GREATER // TODO: Remove here if not necessary. optionsBuilder.UseMySql("----", ServerVersion.FromString("10.5.9")); #endif return(new ProfilerMariaDbContext(optionsBuilder.Options)); }
public ElsaContext CreateDbContext(string[] args) { var builder = new DbContextOptionsBuilder <ElsaContext>(); var connectionString = args.Any() ? args[0] : throw new InvalidOperationException("Please specify a connection string. E.g. dotnet ef database update -- \"Server=localhost;Port=3306;Database=elsa;User=root;Password=password\""); var serverVersion = args.Length >= 2 ? args[1] : null; builder.UseMySql( connectionString, serverVersion != null ? ServerVersion.FromString(serverVersion) : ServerVersion.AutoDetect(connectionString), db => db.MigrationsAssembly(typeof(MySqlElsaContextFactory).Assembly.GetName().Name)); return(new ElsaContext(builder.Options)); }
public static IServiceCollection UseDbConfig <T>(this IServiceCollection services) where T : DbContext { var configuration = services.BuildServiceProvider().GetService <IConfiguration>(); var dataType = configuration["Infrastructure:Database:Use"]; var dbConection = ""; var dbConectionKey = "default"; switch (dataType) { case "MssqlDB": dbConection = configuration[$"Infrastructure:Database:sqlserver{":" + dbConectionKey}"]; break; case "MysqlDB": dbConection = configuration[$"Infrastructure:Database:mysql{":" + dbConectionKey}"]; break; case "Sqlite": default: dbConection = configuration[$"Infrastructure:Database:sqlite{":" + dbConectionKey}"]; break; } switch (dataType) { case "MssqlDB": services.AddDbContextPool <T>(options => options.UseSqlServer(dbConection)); break; case "MysqlDB": services.AddDbContextPool <T>(options => { options.UseMySql(dbConection, ServerVersion.FromString("5.7.33"), mysqlOption => { mysqlOption.CharSet(CharSet.Utf8); }); }); break; case "Sqlite": default: services.AddDbContextPool <T>(options => options.UseSqlite(dbConection)); break; } return(services); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddRazorPages(opt => { opt.Conventions.AuthorizePage("/Privacy"); }); services.AddDbContext <StoreContext>(opt => opt.UseMySql( Configuration.GetConnectionString("StoreContext"), ServerVersion.FromString(Configuration.GetValue <string>("mariadb-version")) )); services.AddDefaultIdentity <WebUser>(opt => opt.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <StoreContext>(); }
protected override void OnConfiguring(DbContextOptionsBuilder options) { // connect to sql server database options.UseMySql( Configuration.GetConnectionString("uaa_mysql_conn"), ServerVersion.FromString("8.0.23"), x => { x.CharSet(CharSet.Utf8Mb4); x.CharSetBehavior(CharSetBehavior.NeverAppend); }) .LogTo(Console.WriteLine) .EnableSensitiveDataLogging() .EnableServiceProviderCaching(); }
public void UseMySql_with_ServerVersion_FromString() { var builder = new DbContextOptionsBuilder(); var serverVersion = ServerVersion.FromString("8.0.21-mysql"); builder.UseMySql( "Server=foo", serverVersion); var mySqlOptions = new MySqlOptions(); mySqlOptions.Initialize(builder.Options); Assert.Equal(new Version(8, 0, 21), mySqlOptions.ServerVersion.Version); Assert.Equal(ServerType.MySql, mySqlOptions.ServerVersion.Type); Assert.Equal("mysql", mySqlOptions.ServerVersion.TypeIdentifier); }
public IServiceCollection Register(IServiceCollection services) { services .AddApplicationInsightsTelemetry() .AddMemoryCache() .AddEntityFrameworkMySql() .AddDbContext <DatabaseContext>(options => { options.UseMySql(_settings.ConnectionString, ServerVersion.FromString("5.7.32-mysql")); }) .AddSingleton(_ => _settings) .AddSingleton <CrossPostServiceFactory>() .AddScoped <ILocalizationService, LocalizationService>() .AddScoped <IPublicationService, PublicationService>() .AddScoped <IUserService, UserService>() .AddScoped <IVacancyService, VacancyService>() .AddScoped <IPublicationRepository, PublicationRepository>() .AddScoped <ISettingsRepository, SettingsRepository>() .AddScoped <ISocialRepository, SocialRepository>() .AddScoped <IPageRepository, PageRepository>() .AddScoped <IUserRepository, UserRepository>() .AddScoped <IVacancyRepository, VacancyRepository>() .AddScoped <IWebAppPublicationService, WebAppPublicationService>() .AddScoped <ILanguageAnalyzerService>(provider => { var logger = provider.GetService <ILogger <LanguageAnalyzerService> >(); return(new LanguageAnalyzerService(_settings.CognitiveServicesTextAnalyticsKey, logger)); }) .AddApplicationInsightsTelemetry(_settings.ApplicationInsights.InstrumentationKey) .Configure <WebEncoderOptions>(options => { options.TextEncoderSettings = new TextEncoderSettings(UnicodeRanges.All); }); return(services); }
public void ConfigureEntityFramework(IServiceCollection services) { services.AddDbContextPool <CarpoolContext>( options => { string connectionString = Configuration["cscp"] ?? Environment.GetEnvironmentVariable("cscp"); options.UseMySql(connectionString, ServerVersion.FromString("8.0.22-mysql"), mySqlOptionsAction: sqlOptions => { sqlOptions.EnableRetryOnFailure( 10, TimeSpan.FromSeconds(5), null ); } ); options.UseLazyLoadingProxies(); }); }
public void Bug_exists_in_MySql57_or_higher() { using var command = Connection.CreateCommand(); command.CommandText = @" SELECT `od1`.`Constant`, `od1`.`OrderID` FROM `Orders` AS `o` LEFT JOIN ( SELECT 'MyConstantValue' AS `Constant`, `od`.`OrderID` FROM `Order Details` AS `od` ) AS `od1` ON `o`.`OrderID` = `od1`.`OrderID` ORDER BY `od1`.`OrderID`;"; using var reader = command.ExecuteReader(); while (reader.Read()) { var constant = reader["Constant"]; var expected = ServerVersion.FromString(Connection.ServerVersion).Supports.MySqlBug96947Workaround ? (object)DBNull.Value : "MyConstantValue"; Assert.Equal(expected, constant); } }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContextPool <AppDbContext>( DbContextOptions => DbContextOptions.UseMySql( Configuration["Db:ConnectionString"], ServerVersion.FromString("8.0.23=mysql"), mySqlOptions => { mySqlOptions.EnableRetryOnFailure( maxRetryCount: 5, maxRetryDelay: TimeSpan.FromSeconds(10), errorNumbersToAdd: null ); }) .EnableDetailedErrors() ); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "api", Version = "v1" }); }); }
protected override void OnConfiguring(DbContextOptionsBuilder options) { options.UseMySql(ConnectionString, ServerVersion.FromString("8.0.20-mysql"), options => options.EnableRetryOnFailure().CharSet(CharSet.Utf8Mb4)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews(); services.AddDbContext <WDPR_BuurtApp_3GContext>(options => options.UseMySql(Configuration.GetConnectionString("WDPR_BuurtApp_3GContextConnectionGezamenlijk"), ServerVersion.FromString("8.0.22-mysql")).UseLazyLoadingProxies()); services.AddRazorPages(); services.AddDefaultIdentity <WDPR_BuurtApp_3GUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddRoles <IdentityRole>() .AddEntityFrameworkStores <WDPR_BuurtApp_3GContext>(); }
/// <summary> /// DI for Maria DB Connection /// </summary> /// <param name="services"></param> /// <param name="configuration"></param> public static void ConfigureMariaDb(this IServiceCollection services, IConfiguration configuration) { services.AddDbContext <MariaDbContext>(options => options.UseMySql(configuration.GetConnectionString("DefaultConnection"), ServerVersion.FromString("10.2.13-mariadb"), b => b.MigrationsAssembly("AngularWebpackVisualStudio"))); }