Persiltech.UserServices.Abstractions 0.1.4

There is a newer version of this package available.
See the version list below for details.
dotnet add package Persiltech.UserServices.Abstractions --version 0.1.4
                    
NuGet\Install-Package Persiltech.UserServices.Abstractions -Version 0.1.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="Persiltech.UserServices.Abstractions" Version="0.1.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Persiltech.UserServices.Abstractions" Version="0.1.4" />
                    
Directory.Packages.props
<PackageReference Include="Persiltech.UserServices.Abstractions" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Persiltech.UserServices.Abstractions --version 0.1.4
                    
#r "nuget: Persiltech.UserServices.Abstractions, 0.1.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.
#:package Persiltech.UserServices.Abstractions@0.1.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Persiltech.UserServices.Abstractions&version=0.1.4
                    
Install as a Cake Addin
#tool nuget:?package=Persiltech.UserServices.Abstractions&version=0.1.4
                    
Install as a Cake Tool

Persiltech.UserServices.Abstractions

NuGet License: MIT

Define la interfaz IUserService, un Output Port que expone el estado de autenticación y la identidad del usuario actual, para que cualquier solución basada en Arquitectura Limpia lo consuma.

Instalación

dotnet add package Persiltech.UserServices.Abstractions

El contrato

namespace Persiltech.UserServices.Abstractions;

public interface IUserService
{
    bool IsAuthenticated { get; }

    string? UserName { get; }

    string? FullName { get; }
}

UserName y FullName son anulables porque el origen de la identidad no garantiza ninguno de los dos: un usuario sin autenticar no los tiene, y uno autenticado puede llegar sin el claim correspondiente. El contrato obliga al consumidor a decidir qué hacer en ese caso en lugar de devolver una cadena vacía que oculte la diferencia.

IsAuthenticated no es anulable: siempre hay una respuesta, aunque sea false.

Uso

using Persiltech.UserServices.Abstractions;

public sealed class CreateOrderHandler(IUserService userService)
{
    public Order Handle(CreateOrderCommand command)
    {
        if (!userService.IsAuthenticated)
        {
            throw new UnauthorizedAccessException();
        }

        return new Order
        {
            Reference = command.Reference,
            CreatedBy = userService.UserName ?? "unknown",
        };
    }
}

Implementar el adaptador

El paquete no trae ninguna implementación: la aporta la solución consumidora, en su capa de infraestructura, junto con el registro en el contenedor. Por ejemplo, resolviendo la identidad desde HttpContext:

using System.Security.Claims;
using Microsoft.AspNetCore.Http;
using Persiltech.UserServices.Abstractions;

public sealed class HttpContextUserService(IHttpContextAccessor httpContextAccessor) : IUserService
{
    private ClaimsPrincipal? User => httpContextAccessor.HttpContext?.User;

    public bool IsAuthenticated => User?.Identity?.IsAuthenticated ?? false;

    public string? UserName => User?.FindFirstValue(ClaimTypes.Name);

    public string? FullName => User?.FindFirstValue(ClaimTypes.GivenName);
}

Y su registro:

builder.Services.AddHttpContextAccessor();
builder.Services.AddScoped<IUserService, HttpContextUserService>();

Tanto el adaptador como el registro pertenecen a la solución consumidora, no a este paquete.

Decisiones de diseño

  • Paquete de puros contratos: no incluye ninguna implementación concreta de IUserService; cada solución consumidora provee su propio adaptador de infraestructura.
  • Sin dependencias a Microsoft.AspNetCore.* ni a ningún framework de hosting, para poder referenciarse desde una capa de dominio o de aplicación sin arrastrar dependencias de infraestructura.
  • Sin registro en el contenedor de dependencias: no hay implementación que registrar.

Compatibilidad

net10.0

Estado

Versión 0.x: la superficie pública puede cambiar entre versiones menores.

Licencia

MIT. Consulta el archivo LICENSE.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Persiltech.UserServices.Abstractions:

Package Downloads
Persiltech.UserServices

Implementación para ASP.NET Core de IUserService, el Output Port que define Persiltech.UserServices.Abstractions, que resuelve la identidad y el estado de autenticación del usuario actual a partir de HttpContext.User.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.12 88 8/20/2026
0.1.11 75 8/19/2026
0.1.10 92 8/19/2026
0.1.9 84 8/19/2026
0.1.8 115 8/18/2026
0.1.7 99 8/18/2026
0.1.6 97 8/18/2026
0.1.5 84 8/18/2026
0.1.4 125 8/11/2026
0.1.3 81 8/10/2026
0.1.2 84 8/10/2026
0.1.1 85 8/10/2026
0.1.0 113 8/10/2026