1
I need to decouple Identity from my Asp.net core MVC layer and play it for another crosscutting layer of my DDD project. Based on Eduardo Pires' Equinox project, I was able to do it, but I’m finding it difficult to activate Migrations. So you’ll understand what I’ve done:
1 - I created the Commercial.Presentation.Web.MVC layer with user authentication. Automatically, the system created several folders, controllers, and classes needed for authentication to work, including the local database. Fantastic!!!!
2 - I created a Commercial System layer.Infra.Crosscutting.Identity.Data and manually created the same folders, controllers and classes as the mvc layer. The idea is to activate Migrations on this layer and then I remove everything from the MVC layer and in this way, the operation would be decoupled and in the Identity layer.
When I try to run "Add-Migration Initialcreate -Context: Applicationdbcontext", the following error msg appears:
Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using 'C:* Local ASP.NET Dataprotection-Keys' as key Repository and Windows DPAPI to Encrypt Keys at Rest. More than one Dbcontext named 'Applicationdbcontext' was found. Specify which one to use by providing its Fully Qualified name using its Exact case.
//Minha classe de contexto na camada Identity
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// get the configuration from the app settings
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json")
.Build();
// define the database to use
optionsBuilder.UseNpgsql(config.GetConnectionString("DefaultConnectionpg"));
}
}
Does anyone know how to help me activate Migrations in the created Identity layer?
Project link: https://onedrive.live.com/? id=40838E65B9F8787E%21120&Cid=40838E65B9F8787E
Hi Gabriel! I removed the context of MVC, but now it is giving this error: "Unable to create an Object of type 'Applicationdbcontext'. Add an implementation of 'Idesigntimedbcontextfactory<Applicationdbcontext>' to the project, or see https://go.microsoft.com/fwlink/? linkid=851728 for Additional Patterns supported at design time."
– Master JR
When executing the powershell, select the project where the context is.
– Gabriel Coletta
I am selecting the project Systemscommercial.Infra.Crosscutting.Identity.Data, only that the error appears..
– Master JR
Share your context with us
– Gabriel Coletta
I will include it in the post... Anything, if you want, you can download the project in the link above to look more detailed.... :)
– Master JR
https://github.com/aspnet/EntityFrameworkCore/issues/9415#issuecomment-327589912
– Gabriel Coletta
I created the implementation class and the Migrations folder was enabled. Only when I give Update-Database, it gives this error: Keyword not supported: 'port'.
– Master JR
Add
--output (seu diretório)
just the front of the command.– Gabriel Coletta
My fault... It worked to give the Update... It was what I was doing for another database... He was trying to insert the tables in another kkkkkkk bank.
– Master JR
Thus: Add-Migration Initial_start -Context: Applicationdbcontext --output Data Migrations?
– Master JR
It’s what I’m doing for the Package Manager Console...
– Master JR
No package Manage console should use -Outputdir ... I got!
– Master JR
Post your reply Gabriel so that I mark it as answered... Thank you :)
– Master JR
We are commenting directly on my reply.
– Gabriel Coletta
Right.. I hadn’t even noticed rsrsr... thanks bro :)
– Master JR