简体   繁体   中英

IActionModelConvention registration in ASP.NET Core 3.1

How can I register IActionModelConvention in ASP.NET Core 3.1? I have a class that implements it:

class MyConvention : IActionModelConvention {
   ...
}

This is how to register it in .NET Core 2.1:

services.AddMvc(options => {
    options.Conventions.Add(new MyConvention());
});

How can I use MyConvention with ASP.NET Core Endpoint Routing?

Try the following:

Within your startup class inside ConfigureServices method use this services.'desired service lifetime'<IActionModelConvention, MyConvention>()

Services life time can be either Transient, Scoped or Singleton, further information you can find in Service Lifetimes

Also take a look at the following article from Microsfto's documentation: Dependency injection in ASP.NET Core

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM