No1.EnvBasedEndpoints 1.0.1

dotnet add package No1.EnvBasedEndpoints --version 1.0.1
                    
NuGet\Install-Package No1.EnvBasedEndpoints -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="No1.EnvBasedEndpoints" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="No1.EnvBasedEndpoints" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="No1.EnvBasedEndpoints" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add No1.EnvBasedEndpoints --version 1.0.1
                    
#r "nuget: No1.EnvBasedEndpoints, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package No1.EnvBasedEndpoints@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=No1.EnvBasedEndpoints&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=No1.EnvBasedEndpoints&version=1.0.1
                    
Install as a Cake Tool

No1.EnvBasedEndpoints

With EnvBasedEndpoints, you can enable or disable specific endpoints or controllers based on specific environments!

Usage

Register EnvironmentControllerFeatureProvider

At the beginning add below code in your program.cs:

using No1.EnvBasedEndpoints;	// import this
//...
var builder = WebApplication.CreateBuilder(args);
var environment = builder.Environment;	// get application's running environment
//...
builder.Services.AddControllers().ConfigureApplicationPartManager(x => EnvironmentControllerFeatureProvider.Register(x, environment));

Now you can use different Attributes based on your requirements:

[NonProduction]

Imagine you need to place a Controller for testing reasons in your app, but you do not want it to be present on production.

It is simple in spring and spring boot. You can add that service conditionally, but in asp.net, there is not such conditionally annotations.

So, you can apply [NonProduction] attribute from this library and then that endpoint exists anywhere but on Production:

[Route("LocalOnly/Test")]
[ApiController]
[NonProduction]
public class TestController : ControllerBase
{
	[HttpGet]
	public void ThrowException() => throw new Exception("Exception Message");
}

[ProductionOnly]

Controllers and endpoints that have this attribute, will be available only in Production environment

[StagingOnly]

Controllers and endpoints that have this attribute, will be available only in Staging environment

[DevelopmentOnly]

Controllers and endpoints that have this attribute, will be available only in Development environment

[EnvironmentAttribute]

This attribute takes two lists. First list of included environments and second, list of excluded environments. Applied controller or endpoint, will be available only if the application is being run under any included envs (if there was any) and none of excluded envs (if there was any)

[Route("LocalOnly/Test")]
[ApiController]
[Environment([], ["Production"])] // Controller will not published on production
public class TestController : ControllerBase
{
	[HttpGet]
	public void ThrowException() => throw new Exception("Exception Message");
}

Building.

For enabling Husky.NET run:

dotnet new tool-manifest
dotnet tool install Husky
git add .husky/pre-commit

After this, Husky formats the code in staged files based on .editorconfig configurations just before commit.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 396 6/14/2026