Use MongoDB for database. Add small migrate function from MySQL

This commit is contained in:
Robert Marshall 2020-06-22 08:18:39 +01:00
parent 313d668bfe
commit 8b240fb077
5 changed files with 31 additions and 5 deletions

View file

@ -3,8 +3,9 @@ using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MongoDB.Driver;
using Robware.Blog;
using Robware.Data;
using Robware.Data.MongoDB;
namespace Robware.Api.Blog {
public class Startup {
@ -19,10 +20,16 @@ namespace Robware.Api.Blog {
services.AddControllers();
services
.AddSingleton<IDatabaseProvider>(new MySQLDatabaseProvider(Configuration.GetConnectionString("database")))
.AddSingleton<Data.IDatabaseProvider>(new Data.MySQLDatabaseProvider(Configuration.GetConnectionString("mysql")))
.AddSingleton<IMongoDatabase>(SetupMongoDatabase())
.AddSingleton<IBlogRepository, BlogRepository>();
}
private IMongoDatabase SetupMongoDatabase() {
var client = new MongoClient(Configuration.GetConnectionString("database"));
return client.GetDatabase("robware");
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if (env.IsDevelopment()) {