Skip to content

Global Using Directives

In many projects we find the same classes are added to the using directives at the top of many class or interface files.

In order to clean up the code a little it is possible to include a global using file in each project.

To do this add a class at the root of the project called something like GlobalUsing.

Delete the actual class and replace with the following for each using statement you want to make global to all files in the project:

global using Carter;
global using Mapster;
global using MediatR;

This is an example of literally what the whole GlobalUsing.cs file would contain (obviously more or other global using statements could be added)

You can now remove the using statements from the individual cs files elsewhere in the project.