need a using directive in the Blazor- use pages,routing etc Exercise:Change navigation

Ed Friesema 21 Reputation points
2025-01-17T18:57:40.7166667+00:00

This example should have a @using BlazingPizza.Services before @inject OrderState OrderState otherwise it throws an error on build

This question is related to the following Learning Module

Blazor Training
Blazor Training
Blazor: A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.Training: Instruction to develop new skills.
16 questions
{count} votes

Accepted answer
  1. Pradeep M 5,605 Reputation points Microsoft Vendor
    2025-01-20T03:41:10.85+00:00

    Hi Ed Friesema,

    Thank you for reaching out to Microsoft Q & A forum. 

    In my experience with this exercise, I did not encounter any issues even without explicitly adding the @using BlazingPizza.Services directive before @inject OrderState OrderState. This is likely because the project we are working on has global usings enabled. Introduced in .NET 6, global usings automatically include common namespaces—such as BlazingPizza.Services—throughout the project, eliminating the need for manual @using declarations. 

    Although it is generally considered good practice to include the @using directive for the sake of clarity, it is not strictly necessary in this case due to the presence of global usings. If you do encounter issues in other environments or projects that do not have global usings enabled, adding the directive manually should resolve the problem. 

    Screenshot for your reference:

    blazormyorders200125

    Please feel free to contact us if you have any additional questions.     

    If you have found the answer provided to be helpful, please click on the "Accept answer/Upvote" button so that it is useful for other members in the Microsoft Q&A community.  

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.