-
Notifications
You must be signed in to change notification settings - Fork 8
REST API with one line of code
Ushakov Michael edited this page Nov 9, 2025
·
9 revisions
This page describes how to use and what limitations Wissance.WebApiToolkit has when we are speaking about the one-line controller feature . Adding a controller in one line occurs without declaring a controller class, thereby we are free from declaring new types in the application and save our time on writing code.
This feature imply following limitations:
- At the current version, the 1-line controller feature is working only with the
EntityFarameworkrelated manager class. - For this feature, we are using either SimplifiedEfModelManager or FullEfModelManager. In case of
SimplifiedEfModelManagerDTOandEntityare the same class. This simplification reduces factory parameters. ButFullModelManagerrequiresManagerConfiguration - Temporarily we are not having authorization for one line controller until this issue is resolved
- Prepare
Entityclass implementedIModelIdentifiable<T> - Get a Controller
Assemblyvia theAddSimplifiedAutoControllerand pass:- Class that derives
DbContext(EntityFramework) - Name of Resource = Name of a Controller without the "Controller" suffix that is using in route ->
api/[Controller] - enum that specifies controller type:
ReadOnly|FullCrud|Bulk
- Class that derives
Example of an instantiation of a controller in one line, split to 2 for the better visual perception:
private void ConfigureWebApi(IServiceCollection services)
{
ServiceProvider provider = services.BuildServiceProvider();
// in one line
Assembly stationControllerAssembly = services.AddSimplifiedAutoController<StationEntity, Guid, EmptyAdditionalFilters>(provider.GetRequiredService<ModelContext>(), "Station", ControllerType.FullCrud, null, provider.GetRequiredService<ILoggerFactory>());
services.AddControllers().AddApplicationPart(sensorControllerAssembly).AddControllersAsServices();
}The full example could be found here: