Skip to content

[Controller]

IntelliTect.Coalesce.DataAnnotations.ControllerAttribute

Allows for control over the generated MVC Controllers.

Currently only controls over the API controllers are present, but additional properties may be added in the future.

This attribute may be placed on any type from which an API controller is generated, including Entity Models, Custom DTOs, and Services.

Example Usage

c#
[Controller(ApiRouted = false, ApiControllerSuffix = "Gen", ApiActionsProtected = true)]
public class Person
{
    public int PersonId { get; set; }
    
    ...
}

Properties

public bool ApiRouted { get; set; } = true;

Determines whether or not a [Route] annotation will be placed on the generated API controller. Set to false to prevent emission of the [Route] attribute.

Use cases include:

  • Defining your routes through IRouteBuilder in Startup.cs instead
  • Preventing API controllers from being exposed by default.
  • Routing to your own custom controller that inherits from the generated API controller in order to implement more granular or complex authorization logic.

public string ApiControllerName { get; set; } = null;

If set, will determine the name of the generated API controller.

Takes precedence over the value of ApiControllerSuffix.

public string ApiControllerSuffix { get; set; } = null;

If set, will be appended to the default name of the API controller generated for this model.

Will be overridden by the value of ApiControllerName if it is set.

public bool ApiActionsProtected { get; set; } = false;

If true, actions on the generated API controller will have an access modifier of protected instead of public.

In order to consume the generated API controller, you must inherit from the generated controller and override each desired generated action method via hiding (i.e. use public new ..., not public override ...).

Note

If you inherit from the generated API controllers and override their methods without setting ApiActionsProtected = true, all non-overridden actions from the generated controller will still be exposed as normal.


Coalesce is a free and open-source framework created by IntelliTect to fill our desire to create better apps, faster. IntelliTect is a high-end software architecture and development consulting firm based in Spokane, Washington.

If you're looking for help with your software project, whether it be a Coalesce application, other technologies, or even just an idea, reach out to us at info@intellitect.com — we'd love to start a conversation! Our clients range from Fortune 100 companies to local small businesses and non-profits.