We have ASP.NET Core solution with standard Microsoft.Extensions.DependencyInjection and need to register certain control depending on configuration setting.
Some Example ApiController that inherits from ControllerBase and all their related actions should only be registered if certain bool is true.
Is this possible? I looked at services.AddMvc() but I didn't see any option that would easily allow me to either:
- Prevent certain
ExampleControllerfrom being registered - Remove
ExampleControllerand all it's related actions fromIServiceCollectionafter being registered
IApplicationFeatureProviderlike in the answer: stackoverflow.com/questions/36680933/… You can implement separateIApplicationFeatureProvider<ControllerFeature>that will filter out specific controller types. You can find simple example in this gist: gist.github.com/Umqra/89b6f26c539a72bdf8c479d5438000dc