Persiltech.UserServices.Abstractions 0.1.0

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

Persiltech.UserServices.Abstractions

NuGet License: MIT

Define 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 sin acoplarse a la infraestructura que resuelve esos datos.

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 de forma deliberada: un usuario anónimo, o un origen de identidad que no publique ese dato, devuelve null.

Uso

Tu capa de aplicación o de dominio depende únicamente de la interfaz:

public sealed class CreateOrderHandler(IUserService userService)
{
    public Task<Guid> HandleAsync(CreateOrderCommand command, CancellationToken cancellationToken)
    {
        if (!userService.IsAuthenticated)
        {
            throw new UnauthorizedAccessException();
        }

        var order = Order.Create(command.Items, createdBy: userService.UserName);

        // ...
    }
}

Implementar el adaptador

Este paquete no incluye ninguna implementación: cada solución provee la suya en su capa de infraestructura, según de dónde salga la identidad. Un adaptador típico para ASP.NET Core:

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

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

    public string? UserName => CurrentUser?.Identity?.Name;

    public string? FullName => CurrentUser?.FindFirst(ClaimTypes.GivenName)?.Value;
}

Y su registro, que también corresponde a la solución consumidora:

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

Decisiones de diseño

  • Paquete de puros contratos. No trae ninguna implementación concreta de IUserService.
  • Sin dependencias. No referencia Microsoft.AspNetCore.* ni ningún framework de hosting, así que puede referenciarse desde una capa de dominio o de aplicación sin arrastrar infraestructura.
  • Sin registro en el contenedor. No hay implementación que registrar, así que el paquete no expone métodos de extensión de IServiceCollection.

Compatibilidad

.NET 10 (net10.0).

Estado

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

Licencia

MIT.

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 91 8/20/2026
0.1.11 77 8/19/2026
0.1.10 94 8/19/2026
0.1.9 85 8/19/2026
0.1.8 117 8/18/2026
0.1.7 101 8/18/2026
0.1.6 99 8/18/2026
0.1.5 86 8/18/2026
0.1.4 127 8/11/2026
0.1.3 83 8/10/2026
0.1.2 86 8/10/2026
0.1.1 87 8/10/2026
0.1.0 115 8/10/2026