This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently it is impossible to create database for the chat sample - `dotnet ef` commands fail with: "No parameterless constructor was found on 'ApplicationDbContext'. Either add a parameterless constructor to 'Application DbContext' or add an implementation of 'IDbContextFactory<ApplicationDbContext>' in the same assembly as 'ApplicationDbC ontext'." - adding IDbContextFactory implementation to fix this Also disabling Redis presence in favor of in-memory presence
- Loading branch information
Showing
2 changed files
with
32 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.IO; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.Infrastructure; | ||
using Microsoft.Extensions.Configuration; | ||
|
||
namespace ChatSample.Data | ||
{ | ||
public class ApplicationDbContextFactory : IDbContextFactory<ApplicationDbContext> | ||
{ | ||
public ApplicationDbContext Create(string[] args) | ||
{ | ||
var configurationBuilder = new ConfigurationBuilder() | ||
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory())) | ||
.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); | ||
|
||
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>(); | ||
optionsBuilder.UseSqlServer(configurationBuilder.Build().GetConnectionString("DefaultConnection")); | ||
|
||
return new ApplicationDbContext(optionsBuilder.Options); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters