Persiltech.UserServices.Abstractions 0.1.2

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.2
                    
NuGet\Install-Package Persiltech.UserServices.Abstractions -Version 0.1.2
                    
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.2" />
                    
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.2" />
                    
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.2
                    
#r "nuget: Persiltech.UserServices.Abstractions, 0.1.2"
                    
#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.2
                    
#: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.2
                    
Install as a Cake Addin
#tool nuget:?package=Persiltech.UserServices.Abstractions&version=0.1.2
                    
Install as a Cake Tool

Persiltech.UserServices.Abstractions

NuGet License: MIT

Output Port IUserService que expone el estado de autenticación y la identidad del usuario actual, para consumirlo desde cualquier solución basada en Arquitectura Limpia.

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 contrato no asume de dónde sale la identidad: un usuario anónimo no tiene ninguno de los dos, y un proveedor de identidad puede autenticar sin emitir el claim correspondiente. Un consumidor que necesite el valor debe tratar null como un caso legítimo, no como un error del adaptador.

Uso

namespace Persiltech.Orders.Application;

public sealed class CreateOrderHandler(IUserService userService)
{
    public string Handle()
    {
        if (!userService.IsAuthenticated)
        {
            return "Se requiere un usuario autenticado.";
        }

        string displayName = userService.FullName ?? userService.UserName ?? "usuario desconocido";

        return $"Pedido creado por {displayName}.";
    }
}

Implementar el adaptador

El paquete no trae implementación ni registro en el contenedor de dependencias. El adaptador y su registro corresponden a la solución consumidora, normalmente en su capa de infraestructura:

namespace Persiltech.Orders.Infrastructure;

public sealed class HttpContextUserService(IHttpContextAccessor httpContextAccessor) : IUserService
{
    public bool IsAuthenticated =>
        httpContextAccessor.HttpContext?.User.Identity?.IsAuthenticated ?? false;

    public string? UserName =>
        httpContextAccessor.HttpContext?.User.Identity?.Name;

    public string? FullName =>
        httpContextAccessor.HttpContext?.User.FindFirst(ClaimTypes.GivenName)?.Value;
}
services.AddHttpContextAccessor();
services.AddScoped<IUserService, HttpContextUserService>();

Decisiones de diseño

  • Paquete de puros contratos: no incluye ninguna implementación concreta de IUserService (Ej. una que la resuelva desde HttpContext.User); cada solución consumidora provee su propio adaptador de infraestructura para el contrato.
  • Sin dependencias a Microsoft.AspNetCore.* ni a ningún framework de hosting, para poder referenciarse desde una capa de dominio/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 91 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