Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
InMemory DB Startup
public class Startup
{
public IConfiguration Configuration { get; }
public IHostingEnvironment CurrentEnvironment { get; }
public Startup(IConfiguration configuration, IHostingEnvironment currentEnvironment)
{
Configuration = configuration;
CurrentEnvironment = currentEnvironment;
}
public void ConfigureServices(IServiceCollection services)
{
if (CurrentEnvironment.IsEnvironment("Testing"))
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseInMemoryDatabase("TestingDB"));
}
else
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
}
// Everything else removed for brevity
}
// Configure Method removed for brevity
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment