Skip to content
HenkKin edited this page Oct 2, 2019 · 5 revisions

Identifiers.AspNetCore

Build Status NuGet NuGet BCH compliance

Summary

The Identifiers.AspNetCore library is an extension on Identifiers.

This library is Cross-platform, supporting netstandard2.1.

Installing Identifiers.AspNetCore

You should install Identifiers.AspNetCore with NuGet:

Install-Package Identifiers.AspNetCore

Or via the .NET Core command line interface:

dotnet add package Identifiers.AspNetCore

Either commands, from Package Manager Console or .NET Core CLI, will download and install Identifiers.AspNetCore and all required dependencies.

Dependencies

Usage

If you're using ASP.NET Core and you want to use this Identifier type in your models, then you can use Identifiers.AspNetCore package which includes a IServiceCollection.AddIdentifiers<[InternalClrType:short|int|long|Guid]>() extension method, allowing you to register all needed RouteConstraints, ModelBinders and JsonConverters.

To use it:

...
using Identifiers.AspNetCore;

public class Startup
{
    ...
    
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddIdentifiers<short|int|long|Guid>();
        ...
    }
    
    ...

Using NSwag

If you're using NSwag and you want to use this Identifier type in your models. Then you have to choose how to expose your Identifier types. Below an example if you want to expose your Identifier type as string:

...
using Identifiers;

public class Startup
{
    ...
    
    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddSwaggerDocument(settings =>
        {
            settings.Title = "Your Service";
            ...
            settings.TypeMappers.Add(new PrimitiveTypeMapper(typeof(Identifier), s => s.Type = JsonObjectType.String));
        });
        ...
    }
    
    ...
Clone this wiki locally