Muslim.Helpers
10.0.1
dotnet add package Muslim.Helpers --version 10.0.1
NuGet\Install-Package Muslim.Helpers -Version 10.0.1
<PackageReference Include="Muslim.Helpers" Version="10.0.1" />
<PackageVersion Include="Muslim.Helpers" Version="10.0.1" />
<PackageReference Include="Muslim.Helpers" />
paket add Muslim.Helpers --version 10.0.1
#r "nuget: Muslim.Helpers, 10.0.1"
#:package Muslim.Helpers@10.0.1
#addin nuget:?package=Muslim.Helpers&version=10.0.1
#tool nuget:?package=Muslim.Helpers&version=10.0.1
Muslim.Helpers
Three small helpers for .NET 10 applications: a contract for the signed-in user, a Base64 file decoder, and an EF Core converter that stores a list of strings in one column.
dotnet add package Muslim.Helpers
| Type | Namespace | What it does |
|---|---|---|
ICurrentUser |
Muslim.Helpers |
The user of the current request |
Base64Data |
Muslim.Core.Common |
Decodes data:image/png;base64,... |
StringListConverter, StringListComparer |
Muslim.Core.EfConverters |
Stores a List<string> as a,b,c |
Current user
The package defines the contract. Your application implements it once:
using System.Security.Claims;
using Muslim.Helpers;
public class CurrentUser(IHttpContextAccessor accessor) : ICurrentUser
{
private ClaimsPrincipal? User => accessor.HttpContext?.User;
public int UserId => int.TryParse(User?.FindFirst("Id")?.Value, out var id) ? id : 0;
public string UserName => User?.Identity?.Name ?? "";
public string Email => User?.FindFirst(ClaimTypes.Email)?.Value ?? "";
public string Phone => User?.FindFirst(ClaimTypes.MobilePhone)?.Value ?? "";
public string UserType => User?.FindFirst("UserType")?.Value ?? "";
public string DeviceToken => User?.FindFirst("DeviceToken")?.Value ?? "";
public string RemoteIpAddress => accessor.HttpContext?.Connection.RemoteIpAddress?.ToString() ?? "";
public IEnumerable<string> Permissions => User?.FindAll("Permission").Select(c => c.Value) ?? [];
public bool IsUserHasPermission(string permission) => Permissions.Contains(permission);
}
Register it:
builder.Services.AddHttpContextAccessor();
builder.Services.AddAutoInjection(typeof(CurrentUser).Assembly);
Then inject ICurrentUser anywhere:
public class OrderService(ICurrentUser currentUser)
{
public bool CanApprove => currentUser.IsUserHasPermission("orders.approve");
}
ICurrentUseris marked for Muslim.Inject, soAddAutoInjectionregisters your class as scoped. NoAddScopedline is needed.- Return
0fromUserIdwhen no one is signed in.
Base64 files
using Muslim.Core.Common;
var file = new Base64Data(request.Image); // "data:image/png;base64,iVBORw0KGgo..."
byte[] bytes = file.Bytes; // the decoded file
string type = file.Extension; // "png"
Extensionis the type exactly as sent:png,jpeg,svg+xml,plain. It is not checked. Compare it with a list of allowed types before you use it in a file name.- Bad input (empty, no type, no comma, invalid Base64) throws
ArgumentExceptionwith the messageinvalid base64 string. The original error is inInnerException. - The whole file is decoded into memory. Limit the request size.
A list of strings in one column
using Muslim.Core.EfConverters;
public class Article
{
public int Id { get; set; }
public List<string> Tags { get; set; } = [];
}
modelBuilder.Entity<Article>().Property(x => x.Tags).HasStringListConversion();
["news", "sport"] is saved as news,sport and read back as a list.
For every List<string> in the model at once:
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
=> configurationBuilder.Properties<List<string>>()
.HaveConversion<StringListConverter, StringListComparer>();
- Always use the comparer with the converter.
HasStringListConversiondoes both. With the converter alone, EF Core does not noticeTags.Add(...)on a loaded entity and saves nothing. - Items must not contain commas.
["a,b"]reads back as["a", "b"]. - An empty list is saved as an empty string and reads back as an empty list.
- Queries that look inside the list, such as
Tags.Contains("news"), cannot run in SQL.
Related packages
| Package | Use it for |
|---|---|
| Muslim.Inject | Automatic dependency registration |
Coding-agent guidance
When you build a project that uses this package, a short guide for AI coding agents is copied to
.agents/skills/muslim-helpers/ at the root of your repository. Agents that read skills from
.agents/skills, such as Codex and GitHub Copilot in VS Code, use it to write correct code against
this package. Your own files and other skills are never touched, and nothing is deleted
automatically.
To turn it off, add this to your project or Directory.Build.props:
<PropertyGroup>
<MuslimHelpersGenerateSkill>false</MuslimHelpersGenerateSkill>
</PropertyGroup>
License
See LICENSE.txt.
| Product | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore.Relational (>= 10.0.13)
- Muslim.Inject (>= 10.0.1)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Muslim.Helpers:
| Package | Downloads |
|---|---|
|
Muslim.GenericRepository
EF Core repository for entities with audit columns: reads, writes, soft delete, bulk operations and raw SQL, with CreatedBy/UpdateBy/DeletedBy and UTC timestamps written automatically. Implements Muslim.GenericRepository.Interface. |
GitHub repositories
This package is not used by any popular GitHub repositories.
StringListConverter now reads an empty column back as an empty list; new StringListComparer and HasStringListConversion make EF Core save in-place list changes. Base64Data keeps the decoding error as InnerException and parses without splitting the whole string. Ships version-matched agent guidance and generates .agents/skills/muslim-helpers during normal consuming builds; preserves user files and supports MuslimHelpersGenerateSkill=false. See CHANGELOG.md and README.md.