WebApiUtilities 1.0.4

dotnet add package WebApiUtilities --version 1.0.4
NuGet\Install-Package WebApiUtilities -Version 1.0.4
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="WebApiUtilities" Version="1.0.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add WebApiUtilities --version 1.0.4
#r "nuget: WebApiUtilities, 1.0.4"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install WebApiUtilities as a Cake Addin
#addin nuget:?package=WebApiUtilities&version=1.0.4

// Install WebApiUtilities as a Cake Tool
#tool nuget:?package=WebApiUtilities&version=1.0.4

WebApiUtilities

WebApiUtilities is a library that contains tools to facilitate the rapid development of RESTful ASP .Net Core 3.1 Web APIs utilising Entity Framework Core, Fluent Validation, Odata and Swagger.

Getting set up

  1. Make a new ASP .Net Core 3.1 Web API project and install the WebApiUtilities nuget package.
  2. For each model you need to add the following classes
    1. Model which inherits Entity<TId> OR AuditableEntity<TId>
    2. DTO which inherits Dto<TModel, TId> and contains the same properties ad TModel
    3. DTO validator which inherits DtoValidator<TDto, Dto> where Dto is the DTO made previously
    4. Model configuration which inherits IEntityTypeConfiguration<TModel>
    5. Optional: If you want to be able to create the model via the API then a Create command which inherits the DTO made previously and ICreateCommand<TModel, TId>
    6. Optional: If you want to be able to update (PUT) the model via the API then an Update Command which inherits the DTO made previously and IUpdateCommand<TModel, TId
    7. A controller which inherits either CrudController<TModel, TId, TCreateComman, TUpdateCommand> OR ReadOnlyController<TModel, TId>
  3. Make a DbContext which inherits either AuditingDbContext OR DbContext
  4. In the ConfigureServices method of Startup.cs configure your DbContext then add the following line.
	services.AddWebApiServices(ApiTitle, ApiVersion);
  1. In the Configure method of Startup.cs add the following
	app.AddWebApiUtilities(GetEdmModel(), MaxTop, ApiVersion);
  1. In Startup.cs add the following method
IEdmModel GetEdmModel()
       {
           var odataBuilder = new ODataConventionModelBuilder();

           //Duplicate this line for each entity
           odataBuilder.EntitySet<TModel>(nameof(TModel));

           return odataBuilder.GetEdmModel();
       }

Adding endpoints

WebAppUtilities utilises MediatR to maintain SOLID principles so it is recommended that for each new endpoint a IRequest and IRequestHandler is made and then in the controller you give the desired request to the mediatr.

To add new endpoints for a model add a new method to the CrudController/ReadOnlyController, decorate it with the desired HTTP method and send the Mediatr the request you made for the endpoint.

To add non entity related endpoints make a new controller which inherits ApiController. This will give to access to the Mediatr to send your request to.

Endpoints

  • API endpoints are available at /api/<TModel>/{id}
  • The Swagger UI is available at /swagger
  • Odata querying is available at /api/<TModel>?$<query string>

Other features

IClock an abstraction around DateTime.Now which is by default bound to the Ioc container at startup and can be injected where needed and mocked in tests.

Product Compatible and additional computed target framework versions.
.NET Framework net is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.4 383 7/26/2020
1.0.3 296 7/26/2020
1.0.2 299 7/19/2020
1.0.1 417 7/19/2020
1.0.0 535 7/18/2020