Skip to content

Commit 6c86601

Browse files
guardrexCopilot
andauthored
Grammar and style NITs with imports file convention (#37543)
* Grammar and style NITs * Apply suggestions from code review Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 5bbf0dc commit 6c86601

69 files changed

Lines changed: 132 additions & 132 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

aspnetcore/blazor/components/class-libraries.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The following characteristics distinguish an RCL from an ASP.NET Core class libr
6565

6666
:::moniker-end
6767

68-
* An RCL references the [`Microsoft.AspNetCore.Components.Web` NuGet package](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Web) and usually relies on an Imports file (`_Imports.razor`) with an `@using` statement for the <xref:Microsoft.AspNetCore.Components.Web?displayProperty=fullName> namespace. The package provides web-specific infrastructure, HTML element abstractions, and event handling bindings required to run Blazor apps inside a web browser.
68+
* An RCL references the [`Microsoft.AspNetCore.Components.Web` NuGet package](https://www.nuget.org/packages/Microsoft.AspNetCore.Components.Web) and usually relies on an imports file (`_Imports.razor`) with an `@using` statement for the <xref:Microsoft.AspNetCore.Components.Web?displayProperty=fullName> namespace. The package provides web-specific infrastructure, HTML element abstractions, and event handling bindings required to run Blazor apps inside a web browser.
6969

7070
## Consume a Razor component from an RCL
7171

@@ -74,7 +74,7 @@ To consume components from an RCL in another project, use either of the followin
7474
* Use the full component type name, which includes the RCL's namespace.
7575
* Individual components can be added by name without the RCL's namespace if Razor's [`@using`](xref:mvc/views/razor#using) directive declares the RCL's namespace. Use the following approaches:
7676
* Add the `@using` directive to individual components.
77-
* Include the `@using` directive in the top-level `_Imports.razor` file to make the library's components available to an entire project. Add the directive to an `_Imports.razor` file at any level to apply the namespace to a single component or set of components within a folder. When an `_Imports.razor` file is used, individual components don't require an `@using` directive for the RCL's namespace.
77+
* Include the `@using` directive in the top-level imports file (`_Imports.razor`) to make the library's components available to an entire project. Add the directive to an imports file at any level to apply the namespace to a single component or set of components within a folder. When an imports file is used, individual components don't require an `@using` directive for the RCL's namespace.
7878

7979
In the following examples, `ComponentLibrary` is an RCL containing the `Component1` component. The `Component1` component is an example component automatically added to an RCL created from the RCL project template that isn't created to support pages and views.
8080

@@ -98,7 +98,7 @@ In the app that consumes the RCL, reference the `Component1` component using its
9898
<ComponentLibrary.Component1 />
9999
```
100100

101-
Alternatively, add a [`@using`](xref:mvc/views/razor#using) directive and use the component without its namespace. The following `@using` directive can also appear in any `_Imports.razor` file in or above the current folder.
101+
Alternatively, add a [`@using`](xref:mvc/views/razor#using) directive and use the component without its namespace. The following `@using` directive can also appear in any imports file (`_Imports.razor`) in or above the current folder.
102102

103103
`ConsumeComponent2.razor`:
104104

aspnetcore/blazor/components/event-handling.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ Register the event handler on one or more HTML elements. Access the data that wa
355355
}
356356
```
357357

358-
If the `@oncustomevent` attribute isn't recognized by [IntelliSense](/visualstudio/ide/using-intellisense), make sure that the component or the `_Imports.razor` file contains an `@using` statement for the namespace containing the `EventHandler` class.
358+
If the `@oncustomevent` attribute isn't recognized by [IntelliSense](/visualstudio/ide/using-intellisense), make sure that the component or the imports file (`_Imports.razor`) contains an `@using` statement for the namespace containing the `EventHandler` class.
359359

360360
Whenever the custom event is fired on the DOM, the event handler is called with the data passed from the JavaScript.
361361

aspnetcore/blazor/components/index.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,14 @@ Typically, a component's namespace is derived from the app's root namespace and
129129
* The `Counter` component's namespace is `BlazorSample.Components.Pages`.
130130
* The fully qualified type name of the component is `BlazorSample.Components.Pages.Counter`.
131131

132-
For custom folders that hold components, add an [`@using`][2] directive to the parent component or to the app's `_Imports.razor` file. The following example makes components in the `AdminComponents` folder available:
132+
For custom folders that hold components, add an [`@using`][2] directive to the parent component or to the app's imports file (`_Imports.razor`). The following example makes components in the `AdminComponents` folder available:
133133

134134
```razor
135135
@using BlazorSample.AdminComponents
136136
```
137137

138138
> [!NOTE]
139-
> [`@using`][2] directives in the `_Imports.razor` file are only applied to Razor files (`.razor`), not C# files (`.cs`).
139+
> [`@using`][2] directives in the imports file (`_Imports.razor`) are only applied to Razor files (`.razor`), not C# files (`.cs`).
140140
141141
Aliased [`using`](/dotnet/csharp/language-reference/keywords/using-directive) statements are supported. In the following example, the public `WeatherForecast` class of the `GridRendering` component is made available as `WeatherForecast` in a component elsewhere in the app:
142142

@@ -188,14 +188,14 @@ Typically, a component's namespace is derived from the app's root namespace and
188188
* The `Counter` component's namespace is `BlazorSample.Pages`.
189189
* The fully qualified type name of the component is `BlazorSample.Pages.Counter`.
190190

191-
For custom folders that hold components, add an [`@using`][2] directive to the parent component or to the app's `_Imports.razor` file. The following example makes components in the `AdminComponents` folder available:
191+
For custom folders that hold components, add an [`@using`][2] directive to the parent component or to the app's imports file (`_Imports.razor`). The following example makes components in the `AdminComponents` folder available:
192192

193193
```razor
194194
@using BlazorSample.AdminComponents
195195
```
196196

197197
> [!NOTE]
198-
> [`@using`][2] directives in the `_Imports.razor` file are only applied to Razor files (`.razor`), not C# files (`.cs`).
198+
> [`@using`][2] directives in the imports file (`_Imports.razor`) are only applied to Razor files (`.razor`), not C# files (`.cs`).
199199
200200
Aliased [`using`](/dotnet/csharp/language-reference/keywords/using-directive) statements are supported. In the following example, the public `WeatherForecast` class of the `GridRendering` component is made available as `WeatherForecast` in a component elsewhere in the app:
201201

@@ -369,7 +369,7 @@ namespace BlazorSample.Pages
369369

370370
:::moniker-end
371371

372-
[`@using`][2] directives in the `_Imports.razor` file are only applied to Razor files (`.razor`), not C# files (`.cs`). Add namespaces to a partial class file as needed.
372+
[`@using`][2] directives in the imports file (`_Imports.razor`) are only applied to Razor files (`.razor`), not C# files (`.cs`). Add namespaces to a partial class file as needed.
373373

374374
Typical namespaces used by components:
375375

@@ -1880,7 +1880,7 @@ Unless the [`@preservewhitespace`](xref:mvc/views/razor#preservewhitespace) dire
18801880
Whitespace removal might affect the rendered output when using a CSS rule, such as `white-space: pre`. To disable this performance optimization and preserve the whitespace, take one of the following actions:
18811881

18821882
* Add the `@preservewhitespace true` directive at the top of the Razor file (`.razor`) to apply the preference to a specific component.
1883-
* Add the `@preservewhitespace true` directive inside an `_Imports.razor` file to apply the preference to a subdirectory or to the entire project.
1883+
* Add the `@preservewhitespace true` directive inside an imports file (`_Imports.razor`) to apply the preference to a subdirectory or to the entire project.
18841884

18851885
In most cases, no action is required, as apps typically continue to behave normally (but faster). If stripping whitespace causes a rendering problem for a particular component, use `@preservewhitespace true` in that component to disable this optimization.
18861886

aspnetcore/blazor/components/layouts.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ In apps that target .NET 10 or earlier, you can adopt the following approach in
105105

106106
Create a wrapper component that's capable of interactivity. In the following example, a wrapper component contains a [Blazor section](xref:blazor/components/sections) that can receive content from a child component.
107107

108-
In the `_Imports.razor` file, add an [`@using`](xref:mvc/views/razor#using) directive for sections (<xref:Microsoft.AspNetCore.Components.Sections?displayProperty=fullName>):
108+
In the imports file (`_Imports.razor`), add an [`@using`](xref:mvc/views/razor#using) directive for sections (<xref:Microsoft.AspNetCore.Components.Sections?displayProperty=fullName>):
109109

110110
```razor
111111
@using Microsoft.AspNetCore.Components.Sections
@@ -174,7 +174,7 @@ Other components around the app can also wrap content in the `InteractiveWrapper
174174

175175
Layout file locations and namespaces changed over time for the Blazor framework. Depending on the version of Blazor and type of Blazor app that you're building, you may need to indicate the layout's namespace when using it. When referencing a layout implementation and the layout isn't found without indicating the layout's namespace, take any of the following approaches:
176176

177-
* Add an `@using` directive to the `_Imports.razor` file for the location of the layouts. In the following example, a folder of layouts with the name `Layout` is inside a `Components` folder, and the app's namespace is `BlazorSample`:
177+
* Add an `@using` directive to the imports file (`_Imports.razor`) for the location of the layouts. In the following example, a folder of layouts with the name `Layout` is inside a `Components` folder, and the app's namespace is `BlazorSample`:
178178

179179
```razor
180180
@using BlazorSample.Components.Layout
@@ -260,12 +260,12 @@ The following rendered HTML markup is produced by the preceding `DoctorWhoLayout
260260

261261
Specifying the layout directly in a component overrides a *default layout*:
262262

263-
* Set by an `@layout` directive imported from an `_Imports.razor` file, as described in the following [Apply a layout to a folder of components](#apply-a-layout-to-a-folder-of-components) section.
263+
* Set by an `@layout` directive imported from an imports file (`_Imports.razor`), as described in the following [Apply a layout to a folder of components](#apply-a-layout-to-a-folder-of-components) section.
264264
* Set as the app's default layout, as described in the [Apply a default layout to an app](#apply-a-default-layout-to-an-app) section later in this article.
265265

266266
### Apply a layout to a folder of components
267267

268-
Every folder of an app can optionally contain a template file named `_Imports.razor`. The compiler includes the directives specified in the imports file in all of the Razor templates in the same folder and recursively in all of its subfolders. Therefore, an `_Imports.razor` file containing `@layout DoctorWhoLayout` ensures that all of the components in a folder use the `DoctorWhoLayout` component. There's no need to repeatedly add `@layout DoctorWhoLayout` to all of the Razor components (`.razor`) within the folder and subfolders.
268+
Every folder of an app can optionally contain an imports file named `_Imports.razor`. The compiler includes the directives specified in the imports file in all of the Razor templates in the same folder and recursively in all of its subfolders. Therefore, an imports file containing `@layout DoctorWhoLayout` ensures that all of the components in a folder use the `DoctorWhoLayout` component. There's no need to repeatedly add `@layout DoctorWhoLayout` to all of the Razor components (`.razor`) within the folder and subfolders.
269269

270270
`_Imports.razor`:
271271

@@ -274,14 +274,14 @@ Every folder of an app can optionally contain a template file named `_Imports.ra
274274
...
275275
```
276276

277-
The `_Imports.razor` file is similar to the [_ViewImports.cshtml file for Razor views and pages](xref:mvc/views/layout#importing-shared-directives) but applied specifically to Razor component files.
277+
The imports file is similar to the [_ViewImports.cshtml file for Razor views and pages](xref:mvc/views/layout#importing-shared-directives) but applied specifically to Razor component files.
278278

279-
Specifying a layout in `_Imports.razor` overrides a layout specified as the router's [default app layout](#apply-a-default-layout-to-an-app), which is described in the following section.
279+
Specifying a layout in the imports file overrides a layout specified as the router's [default app layout](#apply-a-default-layout-to-an-app), which is described in the following section.
280280

281281
> [!WARNING]
282-
> Do **not** add a Razor `@layout` directive to the root `_Imports.razor` file, which results in an infinite loop of layouts. To control the default app layout, specify the layout in the <xref:Microsoft.AspNetCore.Components.Routing.Router> component. For more information, see the following [Apply a default layout to an app](#apply-a-default-layout-to-an-app) section.
282+
> Do **not** add a Razor `@layout` directive to the root imports file, which results in an infinite loop of layouts. To control the default app layout, specify the layout in the <xref:Microsoft.AspNetCore.Components.Routing.Router> component. For more information, see the following [Apply a default layout to an app](#apply-a-default-layout-to-an-app) section.
283283
>
284-
> The same condition results when using an `_Imports.razor` file to apply a layout to a folder of components with the `@layout` directive and the layout component itself is in the same folder or folder hierarchy of the `_Imports.razor` file. An infinite loop of applying the layout occurs because the `@layout` directive is also applied to the layout component. To avoid recursion problems, we recommend storing layout components in their own folder (for example, `Layouts`), away from where `_Imports.razor` files are applying them.
284+
> The same condition results when using an imports file to apply a layout to a folder of components with the `@layout` directive and the layout component itself is in the same folder or folder hierarchy of the imports file. An infinite loop of applying the layout occurs because the `@layout` directive is also applied to the layout component. To avoid recursion problems, we recommend storing layout components in their own folder (for example, `Layouts`), away from where imports files are applying them.
285285
286286
> [!NOTE]
287287
> The [`@layout`](xref:mvc/views/razor#layout) Razor directive only applies a layout to routable Razor components with an [`@page`](xref:mvc/views/razor#page) directive.

aspnetcore/blazor/components/render-modes.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ In the following example, interactive server-side rendering (interactive SSR) is
109109
```
110110

111111
> [!NOTE]
112-
> Blazor templates include a static `using` directive for <xref:Microsoft.AspNetCore.Components.Web.RenderMode> in the app's `_Imports` file (`Components/_Imports.razor`) for shorter `@rendermode` syntax:
112+
> Blazor templates include a static `using` directive for <xref:Microsoft.AspNetCore.Components.Web.RenderMode> in the app's imports file (`Components/_Imports.razor`) for shorter `@rendermode` syntax:
113113
>
114114
> ```razor
115115
> @using static Microsoft.AspNetCore.Components.Web.RenderMode
@@ -671,7 +671,7 @@ The approach described in this subsection is used by the Blazor Web App project
671671

672672
An area (folder) of the app contains the components that must adopt static SSR and only run on the server. The components in the folder share the same route path prefix. For example, the Identity Razor components of the Blazor Web App project template are in the `Components/Account/Pages` folder and share the root path prefix `/account`.
673673

674-
The app also contains an `_Imports.razor` file automatically applied to static SSR components in the `Components` folder, which applies a custom layout.
674+
The app also contains an imports file (`_Imports.razor`) automatically applied to static SSR components in the `Components` folder, which applies a custom layout.
675675

676676
`Components/Account/_Imports.razor`:
677677

@@ -713,7 +713,7 @@ else
713713
```
714714

715715
> [!NOTE]
716-
> In the Blazor Web App project template for authentication scenarios, there's a second layout file (`ManageLayout.razor` in the `Components/Account/Shared` folder) for Identity components in the `Components/Account/Pages/Manage` folder. The `Manage` folder has its own `_Imports.razor` file to apply to the `ManageLayout` to components in the folder. In your own apps, using nested `_Imports.razor` files is a useful approach for applying custom layouts to groups of pages.
716+
> In the Blazor Web App project template for authentication scenarios, there's a second layout file (`ManageLayout.razor` in the `Components/Account/Shared` folder) for Identity components in the `Components/Account/Pages/Manage` folder. The `Manage` folder has its own imports file to apply to the `ManageLayout` to components in the folder. In your own apps, using nested imports files is a useful approach for applying custom layouts to groups of pages.
717717
718718
In the `App` component, any request for a component in the `Account` folder applies a `null` render mode, which enforces static SSR. Other component requests receive a global application of the interactive SSR render mode (`InteractiveServer`).
719719

@@ -742,7 +742,7 @@ In the `App` component, any request for a component in the `Account` folder appl
742742

743743
In the preceding code, change the `{INTERACTIVE RENDER MODE}` placeholder to the appropriate value, depending on if the rest of the application should adopt global <xref:Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveServer>, <xref:Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveWebAssembly>, or <xref:Microsoft.AspNetCore.Components.Web.RenderMode.InteractiveAuto> rendering.
744744

745-
The components that must adopt static SSR in the `Account` folder aren't required to set the layout, which is applied via the `_Imports.razor` file. The components don't set a render mode because they should render with static SSR. Nothing further must be done for the components in the `Account` folder to enforce static SSR.
745+
The components that must adopt static SSR in the `Account` folder aren't required to set the layout, which is applied via the imports file (`_Imports.razor`). The components don't set a render mode because they should render with static SSR. Nothing further must be done for the components in the `Account` folder to enforce static SSR.
746746

747747
### Static SSR components spread out across the app
748748

@@ -834,7 +834,7 @@ Normally, a component uses the following `@rendermode` directive to [disable pre
834834
@rendermode @(new InteractiveServerRenderMode(prerender: false))
835835
```
836836

837-
However, consider the following example that creates a shorthand interactive server-side render mode without prerendering via the app's `_Imports` file (`Components/_Imports.razor`):
837+
However, consider the following example that creates a shorthand interactive server-side render mode without prerendering via the app's imports file (`Components/_Imports.razor`):
838838

839839
```csharp
840840
public static IComponentRenderMode InteractiveServerWithoutPrerendering { get; } =

aspnetcore/blazor/components/sections.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Although the argument passed to <xref:Microsoft.AspNetCore.Components.Sections.S
2727

2828
In the following example, the app's main layout component implements an increment counter button for the app's `Counter` component.
2929

30-
If the namespace for sections isn't in the `_Imports.razor` file, add it:
30+
If the namespace for sections isn't in the imports file (`_Imports.razor`), add it:
3131

3232
```razor
3333
@using Microsoft.AspNetCore.Components.Sections

0 commit comments

Comments
 (0)