diff --git a/Models/Context/SongContext.cs b/Models/Context/SongContext.cs index 6de86f0..8c7fc57 100644 --- a/Models/Context/SongContext.cs +++ b/Models/Context/SongContext.cs @@ -14,15 +14,14 @@ namespace Icarus.Models.Context { public DbSet Songs { get; set; } + + public SongContext(DbContextOptions options) + : base(options) + { } + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(); } - - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseMySQL("server=;database=;user=;password="); - } - } } diff --git a/Startup.cs b/Startup.cs index ae40ca3..66c92a2 100644 --- a/Startup.cs +++ b/Startup.cs @@ -11,8 +11,13 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; +using Microsoft.EntityFrameworkCore; +using MySql.Data; +using MySql.Data.EntityFrameworkCore.Extensions; +using MySql.Data.MySqlClient; using Icarus.Models; +using Icarus.Models.Context; namespace Icarus { @@ -30,8 +35,13 @@ namespace Icarus { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services.AddSingleton(Configuration); + var connString = Configuration.GetConnectionString("DefaultConnection"); - services.Add(new ServiceDescriptor(typeof(MusicStoreContext), new MusicStoreContext(Configuration.GetConnectionString("DefaultConnection")))); + services.Add(new ServiceDescriptor(typeof(MusicStoreContext), + new MusicStoreContext(Configuration + .GetConnectionString("DefaultConnection")))); + + services.AddDbContext(options => options.UseMySQL(connString)); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.