1
votes

I am currently working on a web app using Blazor 3.2 preview 3. I am using the WebAssembly version and Identity. My app consists of 3 parts: Client, Server and Shared. (just like the basic template).

My models classes are stored in the Shared section. However, the model class for Users is stored in the Server folder.

I would like to use in one of my model (stored in the Shared project):

 public virtual ApplicationUser User { get; set; }

This is not possible because the Shared project does not have access to the Server project.

Do I have to put all my models classes in the Server and use DTOs in the Shared part?

Instead put all of my classes in the Shared folder (including ApplicationUsers)?

What’s the best practice?

1

1 Answers

1
votes

This is not possible because the Shared project does not have access to the Server project.

That is not necessary: you could move the ApplicationUser to Shared and add the Microsoft.Extensions.Identity.Stores nuget package to Shared. That is where IdentityUser is defined. However, that would not be a best practice. Amongst other problems it would increase the size of your Client app a lot.

Do I have to put all my models classes in the Server and use DTOs in the Shared part?

That is the preferred pattern, certainly fore a larger project. For something small the distinction between Model classes and DTOs sometimes becomes blurred. But because IdentityUser brings in some dependencies, and contains fields you don't need or want on the client, it would always pay to create an ApplicationUserDto.