GlobalUsings namespace in ASP.NET Core
Controllers & Services
The GlobalUsings.cs file is used to define global using directives. These directives allow you to import namespaces globally, meaning all files in your project automatically have access to them without needing individual using statements.
Creating GlobalUsings.cs. Place this file inside the Infrastructure folder.
global using System; global using System.Collections.Generic; global using Microsoft.AspNetCore.Mvc; global using Microsoft.EntityFrameworkCore;
Razor Views
Creating _ViewImports.cshtml. Place this file inside the /Views folder.
@using Microsoft.AspNetCore.Mvc @using Microsoft.AspNetCore.Mvc.RazorPages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers