Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor context factory #171

Merged
merged 3 commits into from
Aug 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Volvox.Helios.Web/ConfigurationHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.IO;
using Microsoft.Extensions.Configuration;

namespace Volvox.Helios.Web
{
public static class ConfigurationHelper
{
public static IConfiguration GetDefaultConfiguration()
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
return new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("./appsettings.json", optional: false, reloadOnChange: true)
.AddJsonFile($"./appsettings.{environment}.json", optional: true, reloadOnChange: true)
.AddJsonFile("./modulemetadata.json")
.AddUserSecrets<Startup>().Build();
}
}
}
2 changes: 1 addition & 1 deletion src/Volvox.Helios.Web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args)
return WebHost.CreateDefaultBuilder(args)
.UseApplicationInsights()
.UseStartup<Startup>()
.ConfigureAppConfiguration(c => c.AddJsonFile("./modulemetadata.json"))
.UseConfiguration(ConfigurationHelper.GetDefaultConfiguration())
.ConfigureLogging((hostingContext, logging) =>
{
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.Extensions.Configuration;
using Volvox.Helios.Service;

namespace Volvox.Helios.Service
namespace Volvox.Helios.Web
{
public class VolvoxHeliosContextFactory : IDesignTimeDbContextFactory<VolvoxHeliosContext>
{
public VolvoxHeliosContext CreateDbContext(string[] args)
{
var configuration = ConfigurationHelper.GetDefaultConfiguration();

var optionsBuilder = new DbContextOptionsBuilder<VolvoxHeliosContext>();
optionsBuilder.UseSqlServer(
"Server=(localdb)\\mssqllocaldb;Database=VolvoxHelios;Trusted_Connection=True;");

optionsBuilder.UseSqlServer(configuration.GetConnectionString("VolvoxHeliosDatabase"), options=>
options.MigrationsAssembly("Volvox.Helios.Service"));
return new VolvoxHeliosContext(optionsBuilder.Options);
}
}
Expand Down