identity in Clean Architecture #399
-
hi. |
Beta Was this translation helpful? Give feedback.
Replies: 7 comments
-
you can see that identity is part of infrastructure. Look in that project for identity services etc... |
Beta Was this translation helpful? Give feedback.
-
I faced the same situation as @asgharb where I wanted to reference the ApplicationUser in webUI but according to the best practices infrastructure should only be referenced for DI. Should I create an interface IApplicationUser in the application layer and inject it or what? |
Beta Was this translation helpful? Give feedback.
-
Why is the ApplicationUser class in the Infrastructure project? |
Beta Was this translation helpful? Give feedback.
-
I too struggle with this. For learning-purpose I currently build a bug tracker (with Blazor as frontend) and want to use OpenIddict as an IDP. My domain has entities, that need the user (e.g. a project-team consists of many users, a issue/ticket has a user assigned, ...). How should I best handle this? |
Beta Was this translation helpful? Give feedback.
-
Any update on this? |
Beta Was this translation helpful? Give feedback.
-
any update on this ? I also want to reference the user in some of my entities. |
Beta Was this translation helpful? Give feedback.
-
The template isolates If you are not concerned about a dependency on ASP.NET Core Identity, move If you want to remain independent of ASP.NET Core Identity, the missing piece is a public class User
{
public int Id { get; set; }
public string ApplicationUserId { get; set; } // You could also just make this the primary key.
public string Name { get; set; }
public string Email { get; set; }
} This class represents the user within your public class Message
{
public int Id { get; set; }
public int SenderId { get; set; } // This is the user Id foreign key
public string Text { get; set; }
public User Sender { get; set; }
} With the above approach, the Your approach should always depend on the technical requirements of the solution you are building. Happy Coding! 😀 |
Beta Was this translation helpful? Give feedback.
The template isolates
ApplicationUser
withinInfrastructure
, since it depends onIdentityUser
.IdentityUser
comes from ASP.NET Core Identity, and ideally, it's best to avoid dependencies on other frameworks withinCore
(theApplication
andDomain
layers formCore
).If you are not concerned about a dependency on ASP.NET Core Identity, move
ApplicationUser
into theDomain
. It will then be relatively simple to extend Identity and accessApplicationUser
within Core.If you want to remain independent of ASP.NET Core Identity, the missing piece is a
Domain
entity representing your users, let's keep it simple and create aUser
entity in theDomain
: