JCTools.Shortener 1.0.6

There is a newer version of this package available.
See the version list below for details.
dotnet add package JCTools.Shortener --version 1.0.6
NuGet\Install-Package JCTools.Shortener -Version 1.0.6
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="JCTools.Shortener" Version="1.0.6" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JCTools.Shortener --version 1.0.6
#r "nuget: JCTools.Shortener, 1.0.6"
#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 JCTools.Shortener as a Cake Addin
#addin nuget:?package=JCTools.Shortener&version=1.0.6

// Install JCTools.Shortener as a Cake Tool
#tool nuget:?package=JCTools.Shortener&version=1.0.6

JCTools. Shortener

A simple links shortener for include in .net core projects.

Allows add support for create and manage random and unique short links. Its short links are ready for share link to the features or pages of your site.

The short links are created with the letters of the alphabet of the english language and the numerals 0-9, a total use 62 distinct characters.

This characters can will generate more of 57 billions of distinct combinations.

By default, the short links have a longitude between 2 and 6 characters; but, too can configure this longitude.

The longitude and the characters can was changed in the service initialization into the startup class.

Usage

  1. Add the package JCTools.Shortener to your project.
    dotnet add package JCTools.Shortener -v 1.0.6
  1. Implement the interface IDatabaseContext in your database contest
    public class DataContext : Microsoft.EntityFrameworkCore.DbContext, JCTools.Shortener.Settings.IDatabaseContext
    {
        public DataContext(DbContextOptions<DataContext> options)
            : base(options)
        { }
        /// <summary>
        /// the short links collection
        /// </summary>
        public DbSet<ShortLink> ShortLinks { get; set; }

    }
  1. Add the namespace JCTools.Shortener to the startup class
    using JCTools.Shortener;
  1. Configure the shortener service into the ConfigureServices method of the Startup class
    services.AddLinksShortener<DbContext>();
  1. Inject the JCTools.Shortener.Services.ILinkGenerator service
    public class GanttController : Controller
    {
        /// <summary>
        /// the shortener service to be used for share the gantt charts
        /// </summary>
        private readonly ILinkGenerator _shortenerService;

        public GanttController(ILinkGenerator shortenerService)
        {
            ...
    
            this._shortenerService = shortenerService;
    
            ...
        }

        ...

    }
  1. Generate the short link

    ...

    // only generate a token
    var token = await _shortenerService.GenerateTokenAsync();

    // Generate a new entry with a short link
    var realUrl = "https://www.google.com/doodles/"
    var link = await _shortenerServices.GenerateAsync(realUrl);

    // Generate a new entry with a short link and store into the database
    var other = await _shortenerServices. GenerateAndSaveAsync(realUrl); 

    ...

Other settings

In the configuration of the Shortener services into the ConfigureServices method of the Startup class, is possible change the default configuration of the short links.


...
    ...

    services.AddLinksShortener<DbContext>(o => {
        // 1. Change the collection of the characters to be used for generate the short links
        o.ValidCharacters = "1234567890-_qwerty";
        // 2. The min longitude (default 2) of the short links
        o.MinLength = 3; 
        // 2. The max longitude (default 6) of the short links
        o.MaxLength = 10;
        // 3. By default, the access to the redirection action is anonymous
        // It's possible change using a authorization policy  
        o.ConfigurePolicy = p => {
            p.RequireAuthenticatedUser();
            p.RequireRole("admin");
            
            ...
        
        };
    });

    ...

License

This package is released under the MIT license

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 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.1.2 500 12/21/2020
1.1.1 385 12/21/2020
1.1.0 363 12/21/2020
1.0.8 495 6/20/2020
1.0.6 436 3/14/2020