Reputation: 76
The questions are related to a school project.
We have among others the following requirements:
We have free choice of technology and I would like to use this as an oppurtunity to learn more about Blazor. What would be the recommended way of organizing a project in Blazor with both front end and API (contaiing only a subset of the business logic)?
I guess the API and front end can be implemented in the same project using Blazor server? But maybe it is better to have separate projects, and have the front-end (Blazor wasm?) use the api?
All input highly appreciated!
Upvotes: 2
Views: 2700
Reputation: 501
I prefer using WASM project. After creating a Blazor WASM project, I typically restructure it for better organization by dividing the client project into three distinct parts:
The Client Blazor app depends on the Services library, while the Services library relies on the Network library. This arrangement establishes a clear hierarchy among the components.
Please check the ASP.NET + Blazor starting app I maintain on GitHub: https://github.com/devInstance/DevCoreApp/tree/blazor-app. It can provide you with some ideas how to structure Server project and Data Access Layer as well.
Check my article about steps by step designing APIS: https://blog.devinstance.net/a-practical-guide-to-aspnet-applications-designing-robust-crud-webapis-part2
Additionally, you may find my latest article on using Mocks in Blazor WASM project during the UI building phase interesting: https://blog.devinstance.net/implementing-a-mock-driven-approach-in-blazor-applications
Upvotes: 1
Reputation: 76
Answering my own question in case someone else are in the same situation.
I started out with Blazor WASM hosted (dotnet new blazorwasm --hosted
) as suggested by iamrafael. This was a good match for my requirements. If you need authentication/authorization I would include that in the scaffolding from the beginning.
I later found and switched to the template from Blazor Hero, which seems like an excellent starting point for a clean architecture using Blazor wasm and asp.net
Upvotes: 3