Skip to content

HenkKin/Identifiers.AspNetCore

Repository files navigation

Identifiers.AspNetCore

Build Status NuGet NuGet

Summary

The Identifiers.AspNetCore library is an extension on Identifiers.

This library is supporting net5.0.

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));
        });
        ...
    }
    
    ...

Debugging

If you want to debug the source code, thats possible. SourceLink is enabled. To use it, you have to change Visual Studio Debugging options:

Debug => Options => Debugging => General

Set the following settings:

[  ] Enable Just My Code

[X] Enable .NET Framework source stepping

[X] Enable source server support

[X] Enable source link support

Now you can use 'step into' (F11).

About

AspNetCore integration for Identifiers

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages