liveBook · Manning

Global using directive

As explained in .NET MAUI in Action

A global using statement imports a namespace for every source file in a C# project.

A global using directive imports a namespace for every source file in the same C# project, reducing repeated namespace references. C# 10 introduced global using statements. section 7.5.3

Set up project-wide namespace imports with these steps:

  • Add a file named GlobalUsings.cs to the project root. section 7.5.3
  • Remove any template content, leaving the file blank initially. section 7.5.3
  • Add global namespace imports as different project files require them. section 7.5.3

Importing MAUI pages globally

In the MauiStockTake project, GlobalUsings.cs can contain `global using MauiStockTake.UI.Pages;`, making the Pages namespace available throughout the project. section 7.5.3

How .NET MAUI in Action covers it

How deep it goes
Defines project-wide availability, then gives a setup procedure, but does not explore compiler or resolution internals.
Examples
Uses GlobalUsings.cs and the MauiStockTake.UI.Pages namespace as the concrete setup example.
What you can do after
Apply it via a GlobalUsings.cs file to share repeatedly used namespaces across project files.
How it connects
Connects using directives with namespaces, C# projects, and .NET MAUI project setup.

Also explained in

Compare how 2 books explain global using directive →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of .NET MAUI in Action. The section links point to the parts of the book it draws on.