Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ogulcanturan/ogu.aspnetcore.conventions
Custom Asp.Net Core conventions that can be configured in the IMvcBuilder
https://github.com/ogulcanturan/ogu.aspnetcore.conventions
asp-net-core csharp
Last synced: 2 months ago
JSON representation
Custom Asp.Net Core conventions that can be configured in the IMvcBuilder
- Host: GitHub
- URL: https://github.com/ogulcanturan/ogu.aspnetcore.conventions
- Owner: ogulcanturan
- License: apache-2.0
- Created: 2024-05-05T13:58:08.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-09-02T10:13:27.000Z (5 months ago)
- Last Synced: 2024-11-11T21:11:40.764Z (3 months ago)
- Topics: asp-net-core, csharp
- Language: C#
- Homepage:
- Size: 33.2 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Ogu.AspNetCore.Conventions
[![.NET](https://github.com/ogulcanturan/Ogu.AspNetCore.Conventions/actions/workflows/dotnet.yml/badge.svg?branch=master)](https://github.com/ogulcanturan/Ogu.AspNetCore.Conventions/actions/workflows/dotnet.yml)
[![NuGet](https://img.shields.io/nuget/v/Ogu.AspNetCore.Conventions.svg?color=1ecf18)](https://nuget.org/packages/Ogu.AspNetCore.Conventions)
[![Nuget](https://img.shields.io/nuget/dt/Ogu.AspNetCore.Conventions.svg?logo=nuget)](https://nuget.org/packages/Ogu.AspNetCore.Conventions)## Introduction
Ogu.AspNetCore.Conventions is a library which comprising four essential conventions that can be configured in the IMvcBuilder.
## Conventions
- **ControllerAuthorizeConvention:** Simplify authorization configuration by defining authorization rules within your IOC container. This convention allows you to enforce access control policies on controller actions without the need for explicit AuthorizeAttribute annotations.
- **ControllerDisableConvention:** Instead of removing entire controller assemblies, this convention lets you disable individual controllers.
- **ControllerRoutePrefixConvention:** This convention eliminates the need to clutter your controller classes with RouteAttribute annotations, allowing for cleaner and more flexible routing configurations.
- **ControllerHideFromExploringConvention:** prevent controllers from appearing in API documentation.## Installation
You can install the library via NuGet Package Manager:
```bash
dotnet add package Ogu.AspNetCore.Conventions
```## Usage
**ControllerAuthorizeConvention:**
```csharp
public virtual void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers().AddMvcOptions(opts =>
{
// To configure with params => [Authorize(AuthenticationSchemes = "", Policy = "", Roles = "")]
opts.Conventions.AddControllerAuthorizeConvention(conventionOpts =>
{
conventionOpts.AuthenticationSchemes = "";
conventionOpts.Policy = "";
conventionOpts.Roles = "";
});// to use default => [Authorize]
opts.Conventions.AddControllerAuthorizeConvention();
});
...
}
```**ControllerDisableConvention:**
```csharp
public virtual void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers().AddMvcOptions(opts =>
{
opts.Conventions.AddControllerDisableConvention();
});
...
}
```**ControllerRoutePrefixConvention:**
```csharp
public virtual void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers().AddMvcOptions(opts =>
{
opts.Conventions.AddControllerRoutePrefixConvention("api/launcher");
});
...
}
```**ControllerHideFromExploringConvention:**
```csharp
public virtual void ConfigureServices(IServiceCollection services)
{
...
services.AddControllers().AddMvcOptions(opts =>
{
opts.Conventions.AddControllerHideFromExploringConvention();
});
...
}
```## Sample Application
A sample application demonstrating the usage of Ogu.AspNetCore.Conventions can be found [here](https://github.com/ogulcanturan/Ogu.AspNetCore.Conventions/tree/master/samples/).