This project contains some utilities that I was tired of copying from project to project or that I decided to add to facilitate my life (like Azure table repository, this is a great time saver and Dynamic InternalServerError, that handle Exceptions in web APIs for me).
This is a work in progress.
I do not manage version number yet; it is still too early. Version numbers are autoincremented by automatic builds.
ForEvolve NuGet V3 feed URL packages source. See the Table of content project for more info.
You can find the meta-package that references all ForEvolve.* projects at the following repo: ForEvolve/MetaPackages.
This project aims at adding features over ApplicationInsights.
For now, it contains only a TrackExceptionsFilterAttribute.
This project aims at adding features over Asp.Net Core.
var myHttpContent = myObject.ToJsonHttpContent();var myJsonString = myObject.ToJson();var myObject = myHttpContent.ReadAsJsonObjectAsync<MyObjectType>();var myObject = anyString.ToObject<MyObjectType>();AddRequestIdMiddlewareis a middleware that adds an HTTP Header containing a request id. This is useful if your system must do multiple remote HTTP calls, like in a Microservices architecture or a distributed system.SetRequestIdAsTraceIdentifieris a middleware that set theHttpContext.TraceIdentifierto the request id HTTP Header (set byAddRequestIdMiddleware). It also allows transferring the request id header to the HTTP response (for client-side tracing).
IViewRendererAllow you to render a view to string.
This project aims at adding features over the Azure SDK like Object (Blob), Queue, Table and KeyVault repositories.
I will write more docs later for this one...
This project holds shared classes. For now, it only contains ForEvolveException.
A dynamic internal server error filter for ASP.NET Core, targetting Asp.Net Core 2.0, that translate Exceptions (status code 500) to JSON automatically.
Validation errors are also translated automatically, following the same convention, for response with status code 400.
The error model is based on: Microsoft REST API Guidelines.
In your Startup class, you must AddDynamicInternalServerError() to add dependencies and ConfigureDynamicInternalServerError() to add the filter to MVC.
public void ConfigureServices(IServiceCollection services)
{
// Add DynamicInternalServerError
services.AddDynamicInternalServerError();
// Add framework services.
services.AddMvc(options =>
{
options.ConfigureDynamicInternalServerError();
});
}Thats it, now exceptions are translated to JSON.
In the ConfigureServices method, you must add services.AddDynamicInternalServerErrorSwagger();.
In the services.AddSwaggerGen(c => { ... }) you must register swagger operation filters by calling c.AddDynamicInternalServerError();.
public void ConfigureServices(IServiceCollection services)
{
// Add DynamicInternalServerError
services.AddDynamicInternalServerError();
services.AddDynamicInternalServerErrorSwagger();
// Add framework services.
services.AddMvc(options =>
{
options.ConfigureDynamicInternalServerError();
});
// Add and configure Swagger.
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
// Add and configure DynamicInternalServerError.
c.AddDynamicInternalServerError();
});
}DynamicValidationActionFilter translates BadRequestObjectResult that has a value of type SerializableError to an ErrorResponse object, following the same convention as DynamicValidationActionFilter do.
By default, by registering DynamicInternalServerError you also register DynamicValidation.
Return BadRequest(ModelState); in a controller action. To define ErrorResponse automatically in the swagger definition file, simply decorat the action with [ProducesResponseType(400)] (do not specify a type).
[HttpPost]
[ProducesResponseType(400)]
public IActionResult Post([FromBody]string value)
{
if(!ModelState.IsValid)
{
return BadRequest(ModelState);
}
// ...
}This project contains some XUnit test utilities like:
IdentityHelperthat creates the plumbing to MockSignInManagerandUserManager.HttpContextHelperthat creates the plumbing to MockHttpContextandHttpRequest.MvcContextHelperat creates the plumbing to MockIUrlHelperandActionContext.BaseStartupExtensionsTestis a base class to help test startup extensions.
I plan on evolving theses libraries as I use them in multiple projects.
Examples of what I want to add:
- Azure table repository with memory cache (to save HTTP calls)
- Azure table repository with distributed cache (to save HTTP calls)
- Azure table repository with both memory and distributed cache (decorators?)
- Azure table batch operations
- Azure cognitive services helpers
- Easy Azure Cosmos DB support
- ...
If you would like to contribute to the Framework, feel free to contact me.