// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddCors(options => { options.AddDefaultPolicy(builder => { builder.AllowAnyOrigin(); builder.AllowAnyHeader(); builder.AllowAnyMethod(); }); }); services.AddControllers(); services.AddResponseCompression(); const string connectionString = ""; var serverVersion = new MySqlServerVersion(new Version(5, 6, 50)); services.AddDbContextPool <MainDbContext>( dbContextOptions => dbContextOptions .UseMySql(connectionString, serverVersion) .EnableSensitiveDataLogging() // These two calls are optional but help .EnableDetailedErrors()); // with debugging (remove for production). services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "ErogeHelper.Server", Version = "v1" }); }); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { //Dependency Injection: //Choose which architecture to implement //Either database architecture or runtime repository services.AddTransient <IContestRepo, ContestDatabase>(); services.AddTransient <IDiverRepo, DiverDatabase>(); services.AddTransient <IParticipantRepo, ParticipantsDatabase>(); services.AddTransient <IJudgeRepo, JudgeDatabase>(); services.AddTransient <IJudgeParticipantRepo, JudgeParticipantDatabase>(); services.AddTransient <IEventsRepo, EventsDatabase>(); services.AddTransient <IFinaDifficultyRepo, FinaDifficultyDatabase>(); services.AddControllers(); var connection = "server=localhost;user id=root;database=DiveComp;password=1234"; var serverVersion = new MySqlServerVersion(new Version(8, 0, 24)); services.AddDbContextPool <ModelContext>( DbContextOptions => DbContextOptions .UseMySql(connection, serverVersion) //.EnableSensitiveDataLogging() //these two used for debugging, will not be in final version //.EnableDetailedErrors() ); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.Configure <Settings>(Configuration.GetSection("Configuration")); // Replace with your server version and type. // Use 'MariaDbServerVersion' for MariaDB. // Alternatively, use 'ServerVersion.AutoDetect(connectionString)'. // For common usages, see pull request #1233. var serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); // Replace 'YourDbContext' with the name of your own DbContext derived class. services.AddDbContext <WebsiteContext>( dbContextOptions => dbContextOptions .UseMySql(Configuration.GetSection("Configuration").GetSection("ConnectionString").Value, serverVersion) .EnableSensitiveDataLogging() // <-- These two calls are optional but help .EnableDetailedErrors() // <-- with debugging (remove for production). ); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddDistributedMemoryCache(); services.AddSession(options => { options.IdleTimeout = TimeSpan.FromSeconds(10); options.Cookie.HttpOnly = true; options.Cookie.IsEssential = true; }); services.AddControllersWithViews(); }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { var serverVersion = new MySqlServerVersion(new Version(8, 0, 27)); optionsBuilder.UseMySql(configuration.GetConnectionString("DefaultConnection"), serverVersion); optionsBuilder.UseLoggerFactory(_loggerFactory); base.OnConfiguring(optionsBuilder); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionStreing = Configuration.GetConnectionString("orderDB"); var serverVersion = new MySqlServerVersion(new Version(8, 0, 23)); services.AddDbContextPool <OrderContext>(options => options.UseMySql(connectionStreing, serverVersion)); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var serverVersion = new MySqlServerVersion(new Version(10, 4, 18)); services.AddControllersWithViews(); services.AddDbContext <NewsDbContext>(options => options.UseMySql(Configuration .GetConnectionString("NewsDbContext"), serverVersion)); }
public AdoptionMigrationsDbContext CreateDbContext(string[] args) { var configuration = BuildConfiguration(); var serverVersion = new MySqlServerVersion(new Version(configuration["DefaultMysqlVersion"])); var builder = new DbContextOptionsBuilder <AdoptionMigrationsDbContext>() .UseMySql(configuration.GetConnectionString("Default"), serverVersion); return(new AdoptionMigrationsDbContext(builder.Options)); }
public static void AddInfrastructure(this IServiceCollection services, string connectionString) { var assembly = Assembly.GetExecutingAssembly(); var version = Assembly.GetEntryAssembly().GetName().Version; var serverVersion = new MySqlServerVersion(new Version(version.Major, version.Minor, version.Build)); services.AddScoped <DbConnection>(provider => { var connection = new MySqlConnection(connectionString); connection.Open(); return(connection); }); services.AddScoped <IList <DbContext> >(serviceProvider => GetAllDbContextInstances(serviceProvider).ToList()); services.AddDbContext <ShoppingListContext>( (serviceProvider, options) => { var connection = serviceProvider.GetService <DbConnection>(); options.UseMySql(connection, serverVersion); }); services.AddDbContext <ItemCategoryContext>( (serviceProvider, options) => { var connection = serviceProvider.GetService <DbConnection>(); options.UseMySql(connection, serverVersion); }); services.AddDbContext <ManufacturerContext>( (serviceProvider, options) => { var connection = serviceProvider.GetService <DbConnection>(); options.UseMySql(connection, serverVersion); }); services.AddDbContext <ItemContext>( (serviceProvider, options) => { var connection = serviceProvider.GetService <DbConnection>(); options.UseMySql(connection, serverVersion); }); services.AddDbContext <StoreContext>( (serviceProvider, options) => { var connection = serviceProvider.GetService <DbConnection>(); options.UseMySql(connection, serverVersion); }); services.AddTransient <IShoppingListRepository, ShoppingListRepository>(); services.AddTransient <IItemRepository, ItemRepository>(); services.AddTransient <IItemCategoryRepository, ItemCategoryRepository>(); services.AddTransient <IManufacturerRepository, ManufacturerRepository>(); services.AddTransient <IStoreRepository, StoreRepository>(); services.AddScoped <ITransactionGenerator, TransactionGenerator>(); services.AddInstancesOfGenericType(assembly, typeof(IToEntityConverter <,>)); services.AddInstancesOfGenericType(assembly, typeof(IToDomainConverter <,>)); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetConnectionString("OrderDatabase"); var serverVersion = new MySqlServerVersion(new Version(8, 0, 25)); //services.AddDbContext<OrderDBContext>(opt => opt.UseInMemoryDatabase("OrderDatabase")); services.AddDbContextPool <OrderDBContext>(options => options.UseMySql(connectionString, serverVersion)); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddOptions(); services.AddRazorPages(); services.AddMemoryCache(); services.AddHttpClient(); services.AddControllers().AddNewtonsoftJson(); services.AddHealthChecks(); services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme) .AddJwtBearer(options => { options.TokenValidationParameters = new TokenValidationParameters() { ValidateIssuer = false, ValidateAudience = false, ValidateLifetime = false, ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Configuration["Jwt:Key"])) }; }); services.AddScoped <IHubUsersStorage, SqlServerHubUsersStorage>(); services.AddCors(options => { options.AddDefaultPolicy(cb => cb .AllowAnyMethod() .AllowAnyHeader() .AllowAnyOrigin()); options.AddPolicy("CorsPolicy", cb => cb .AllowAnyMethod() .AllowAnyHeader() .AllowAnyOrigin() ); } ); services.AddSignalR().AddJsonProtocol(); var serverVersion = new MySqlServerVersion(new Version(5, 7, 0)); services.AddDbContext <FightTimelineDataContext>(builder => { builder.ConfigureWarnings(warnings => warnings .Ignore(CoreEventId.ContextInitialized) .Ignore(CoreEventId.ContextDisposed)); builder.UseMySql(Configuration.GetConnectionString("Default"), serverVersion); }); // In production, the Angular files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); }
public static IServiceCollection AddEfCoreAndIdentity(this IServiceCollection services, IConfiguration config) { var connectionString = config.GetConnectionString("MySQL"); var mySqlVersion = new MySqlServerVersion(Version.Parse(config["DbProviders:MySQL:Version"])); services .AddDbContext <AppDbContext>(options => options.UseMySql(connectionString, mySqlVersion)) .AddIdentity <AppUser, IdentityRole>() .AddEntityFrameworkStores <AppDbContext>(); return(services); }
public void ConfigureServices(IServiceCollection services) { var connectionString = "server=localhost;user=root;password=xyf563214789;database=orderdb2;"; var serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); services.AddDbContext <OrderContext>( dbContextOptions => dbContextOptions .UseMySql(connectionString, serverVersion)); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = "Server=localhost;Database=FlowersDB;Password=root;User=root"; var serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); //services.AddScoped<IAuthorizationHandler, AuthorizationHandler>(); //services.AddScoped<IAuthTokenService, AuthTokenService>(); //services.AddScoped<ITokenRepository, TokenSqlRepository>(); //services.AddAuthorization(options => //{ // options.AddPolicy("Token", policy => // policy.Requirements.Add(new AuthTokenRequirement())); //}); services.AddMvc(config => { //config.Filters.Add(new AuthorizeFilter("Token")); }); // In production, the React files will be served from this directory services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/build"; }); services.AddLogging(); services.AddLocalization(options => options.ResourcesPath = "Resources"); services.AddSimpleInjector(container, options => { options.AddAspNetCore() .AddControllerActivation() .AddViewComponentActivation(); options.AddLogging(); options.AddLocalization(); }); services.AddDbContext <Superjonikai.DB.DBContext>(options => options .UseLazyLoadingProxies() .UseMySql(Configuration.GetConnectionString("DefaultConnection"), serverVersion)); if (Convert.ToBoolean(Configuration.GetSection("LoggingEnabled").Value)) { services.AddMvc(opts => { opts.Filters.Add(new LogActionFilter()); }); } InitializeContainer(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { // Configuração do MySQL string stringConexao = "Server=localhost;DataBase=CadastroWeb;Uid=root"; var serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); services.AddDbContext <Contexto>(options => options.UseMySql(stringConexao, serverVersion)); //Utilizado MySQL.Data.EntityFrameworkCore para UseMySQL services.AddControllersWithViews(); }
public static void ConfigureDependenciesService(IServiceCollection serviceDescriptors) { var serverVersion = new MySqlServerVersion(new Version(8, 0, 27)); serviceDescriptors.AddDbContext <MyContext>( options => options.UseMySql("Server=localhost;Port=3306;Database=supermarket;Uid=root;Pwd=P@ssw0rd", serverVersion) ); serviceDescriptors.AddScoped(typeof(IRepository <>), typeof(BaseRepository <>)); serviceDescriptors.AddScoped <IUserRepository, UserRepository>(); serviceDescriptors.AddScoped <IProductRepository, ProductRepository>(); }
public static NuGetApiOptions AddMySqlDatabase(this NuGetApiOptions options) { options.Services.AddNuGetApiOptions <MySqlDatabaseOptions>(nameof(PackageFeedOptions.Database)); options.Services.AddNuGetFeedDbContextProvider <MySqlContext>("MySql", (provider, builder) => { var databaseOptions = provider.GetRequiredService <IOptionsSnapshot <MySqlDatabaseOptions> >(); var version = new MySqlServerVersion(databaseOptions.Value.Version); builder.UseMySql(databaseOptions.Value.ConnectionString, version); }); return(options); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); services.AddDbContext <AppDbContext>(options => options.UseMySql( Configuration.GetConnectionString("DefaultConnection"), serverVersion)); services.AddDatabaseDeveloperPageExceptionFilter(); services.AddDefaultIdentity <IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddEntityFrameworkStores <AppDbContext>(); services.AddControllersWithViews(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetConnectionString("DefaultConnection"); var serverVersion = new MySqlServerVersion(new Version(8, 0, 25)); services.AddDbContext <BookStoreContext>( dbContextOptions => dbContextOptions .UseMySql(connectionString, serverVersion)); services.AddControllers(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); var connectionString = "Server=localhost;Database=gestao_de_gastos;User=root;Password=root;"; var serverVersion = new MySqlServerVersion(new Version(8, 0, 25)); services.AddDbContextPool <DataContext>( options => options.UseMySql(connectionString, serverVersion) .EnableSensitiveDataLogging() .EnableDetailedErrors() ); services.AddMvc(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connectionString = Configuration.GetConnectionString("Sales3Context"); var serverVersion = new MySqlServerVersion(new Version(8, 0, 25)); services.AddControllersWithViews(); services.AddDbContext <Sales3Context>(options => options.UseMySql(connectionString, serverVersion, builder => builder.MigrationsAssembly("Sales3"))); services.AddScoped <SeedingService>(); services.AddScoped <SellerService>(); services.AddScoped <DepartmentService>(); services.AddScoped <SalesRecordService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var mysqlConn = Configuration.GetConnectionString("DefaultConnection"); var serverVersion = new MySqlServerVersion(new Version(5, 7, 33)); services.AddDbContext <ApplicationDbContext>(options => options.UseMySql(mysqlConn, serverVersion) ); services.AddHsts(options => { options.Preload = true; options.IncludeSubDomains = true; options.MaxAge = TimeSpan.FromDays(365); }); services.AddDefaultIdentity <SiteUser>(options => options.SignIn.RequireConfirmedAccount = true) .AddRoles <IdentityRole>() .AddRoleManager <RoleManager <IdentityRole> >() .AddErrorDescriber <DanishIdentityErrorDescriber>() .AddEntityFrameworkStores <ApplicationDbContext>() .AddDefaultTokenProviders(); services.AddTransient <IEmailSender, EmailSender>(i => new EmailSender( Configuration["EmailSender:Host"], Configuration.GetValue <int>("EmailSender:Port"), Configuration.GetValue <bool>("EmailSender:EnableSSL"), Configuration["EmailSender:UserName"], Configuration["EmailSender:Password"] ) ); services.AddScoped <IStripeService, StripeService>(i => new StripeService()); services.AddScoped <IIndexService, GithubService>(i => new GithubService( Configuration["GitHub:ContentAPI"], Configuration["GitHub:Token"] ) ); StripeConfiguration.ApiKey = Configuration["StripeConfig:SecretApiKey"]; services.AddScoped <ISmsSender, SmsSender>(i => new SmsSender( Configuration["SmsSender:Host"], Configuration["SmsSender:ApiKey"], Configuration["SmsSender:From"] ) ); services.AddControllersWithViews(); services.AddRazorPages(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "CompanyApi", Version = "v1" }); }); var serverVersion = new MySqlServerVersion(new Version(10, 4, 18)); services.AddDbContext <CompanyDbContext>(options => options.UseMySql(Configuration .GetConnectionString("CompanyDbContext"), serverVersion)); }
protected override void OnConfiguring(DbContextOptionsBuilder options) { var config = new ConfigurationBuilder() .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .Build(); //if (Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT").ToUpper() == "DEVILOPMENT") //{ var serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); options.UseMySql(config.GetConnectionString("DefaultConnection"), serverVersion); //} //else //{ //options.UseSqlServer(config.GetConnectionString("SQLServer")); //} }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var connection = Configuration.GetConnectionString("OrderDatabase"); var serverVersion = new MySqlServerVersion(new Version(8, 0, 24)); services.AddDbContextPool <OrderContext>(options => options .UseMySql(connection, serverVersion) ); services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "OrderWeb", Version = "v1" }); }); }
static void Main(string[] args) { var host = Host.CreateDefaultBuilder() .ConfigureServices((context, services) => { services.AddSingleton <IAppHost, AppHost>(); services.AddSingleton <IWebhookClient, WebhookClient>(); services.AddDbContext <SendAgentDbContext>(opt => opt.UseMySql(context.Configuration.GetConnectionString("AirlineConnection"), MySqlServerVersion.AutoDetect(context.Configuration.GetConnectionString("AirlineConnection"))) ); services.AddHttpClient(); }).Build(); host.Services.GetService <IAppHost>().Run(); }
/// <summary> /// Handle connection to MariaDB database /// </summary> /// <param name="optionsBuilder">Connection options object</param> private void ConnectToMariaDB(DbContextOptionsBuilder optionsBuilder) { try { DatabaseConfig.ParamMariaDB Options = JsonConvert.DeserializeObject <DatabaseConfig.ParamMariaDB>(DatabaseConfig.Instance.DatabaseOptions); var connectionString = @"server={Options.Server};port={Options.Port};database={Options.Database};user={Options.UserId};password={Options.Password}"; var serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); optionsBuilder.UseMySql(connectionString, serverVersion, options => { options.MigrationsAssembly(Assembly.GetExecutingAssembly().FullName); }); } catch (Exception e) { System.Console.WriteLine($"{nameof(ConnectToMariaDB)}: Invalid config object [{DatabaseConfig.Instance.DatabaseOptions}] for MariaDB recieved - exception [{e.Message}]."); } }
public static void UseMySqlWithLazyLoading(this DbContextOptionsBuilder optionsBuilder, DataConnectionConfig config, string connStr) { var serverVersion = new MySqlServerVersion(new Version(config.VersionNumber)); optionsBuilder.UseMySql(connStr, serverVersion, builder => { builder.EnableRetryOnFailure(maxRetryCount: 5); if (config.IsTenantShardingTable) { builder.MigrationsHistoryTable( $"__EFMigrationsHistory{EngineContext.Current.GetSafeShardingTableSuffix()}"); } }); optionsBuilder.UseBatchEF_MySQLPomelo(); }
public void ConfigureServices(IServiceCollection services) { services.AddLogging((Action <ILoggingBuilder>)(logggingBuilder => logggingBuilder.AddNLog("nlog.config"))); MySqlServerVersion serverVersion = new MySqlServerVersion(new Version(8, 0, 21)); if (this.CurrentEnvironment.IsDevelopment()) { services.AddDbContext <AppDbContext>((Action <DbContextOptionsBuilder>)(options => options.UseMySql(this.Configuration.GetConnectionString("DefaultConnection"), (ServerVersion)serverVersion, (Action <MySqlDbContextOptionsBuilder>)(options => options.MigrationsAssembly("ThesisProject.Data"))))); } else { services.AddDbContext <AppDbContext>((Action <DbContextOptionsBuilder>)(options => options.UseSqlServer(this.Configuration.GetConnectionString("SQLServer")))); } services.AddDatabaseDeveloperPageExceptionFilter(); services.AddDefaultIdentity <AppUser>((Action <IdentityOptions>)(options => { options.SignIn.RequireConfirmedAccount = false; options.Password.RequireDigit = false; options.Password.RequireUppercase = false; options.Password.RequireLowercase = false; options.Password.RequireNonAlphanumeric = false; options.Password.RequiredLength = 1; options.Password.RequiredUniqueChars = 1; })).AddRoles <IdentityRole>().AddEntityFrameworkStores <AppDbContext>(); services.AddAuthentication().AddFacebook((Action <FacebookOptions>)(facebookOptions => { facebookOptions.AppId = this.Configuration["Authentication:Facebook:AppId"]; facebookOptions.AppSecret = this.Configuration["Authentication:Facebook:AppSecret"]; facebookOptions.AccessDeniedPath = (PathString)"/Login"; })); services.AddControllersWithViews().AddRazorRuntimeCompilation(); IConfigurationSection section = this.Configuration.GetSection("EmailSettings"); services.Configure <EmailSettings>((IConfiguration)section); services.AddRazorPages(); services.AddScoped <IIdentityService, IdentityService>(); services.AddTransient <IEmailSender, ThesisProject.WebApp.Services.EmailSender>(); services.AddScoped <IDoctorService, DoctorService>(); services.AddScoped <IPacientService, PacientService>(); services.AddScoped <IScheduleService, ScheduleService>(); services.AddScoped <IUserService, UserService>(); services.AddScoped <ICardService, CardService>(); services.AddScoped <IServicesService, ServicesService>(); services.AddScoped <IStatsService, StatsService>(); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "GameTrack", Version = "v1" }); }); // setup connection string services.AddDbContextFactory <GameTrackDbContext>(opt => opt.UseMySql( Configuration.GetConnectionString("GameTrackConnectionString"), MySqlServerVersion.AutoDetect(Configuration.GetConnectionString("GameTrackConnectionString"))) ); // services.AddAutoMapper(AppDomain.CurrentDomain.GetAssemblies()); }
// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddControllers(); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title = "StreamReady_backend", Version = "v1" }); }); var connectionString = Configuration.GetConnectionString("Default"); var serverVersion = new MySqlServerVersion(new Version(8, 0, 22)); services.AddDbContext <AppDbContext>( dbContextOptions => dbContextOptions .UseMySql(connectionString, serverVersion) ); }