Siemens.AspNet.MinimalApi.Sdk.Contracts 0.1.0-alpha.84

Prefix Reserved
This is a prerelease version of Siemens.AspNet.MinimalApi.Sdk.Contracts.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Siemens.AspNet.MinimalApi.Sdk.Contracts --version 0.1.0-alpha.84
                    
NuGet\Install-Package Siemens.AspNet.MinimalApi.Sdk.Contracts -Version 0.1.0-alpha.84
                    
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="Siemens.AspNet.MinimalApi.Sdk.Contracts" Version="0.1.0-alpha.84" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Siemens.AspNet.MinimalApi.Sdk.Contracts" Version="0.1.0-alpha.84" />
                    
Directory.Packages.props
<PackageReference Include="Siemens.AspNet.MinimalApi.Sdk.Contracts" />
                    
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 Siemens.AspNet.MinimalApi.Sdk.Contracts --version 0.1.0-alpha.84
                    
#r "nuget: Siemens.AspNet.MinimalApi.Sdk.Contracts, 0.1.0-alpha.84"
                    
#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 Siemens.AspNet.MinimalApi.Sdk.Contracts@0.1.0-alpha.84
                    
#: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=Siemens.AspNet.MinimalApi.Sdk.Contracts&version=0.1.0-alpha.84&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Siemens.AspNet.MinimalApi.Sdk.Contracts&version=0.1.0-alpha.84&prerelease
                    
Install as a Cake Tool

Siemens.AspNet.MinimalApi.Sdk.Contracts

The Siemens.AspNet.MinimalApi.Sdk.Contracts NuGet package defines essential interfaces, attributes, and base classes designed to standardize common functionalities required for building Minimal APIs. These abstractions support dependency injection, JSON serialization, difference tracking, and advanced validation scenarios.


📖 Overview

This package provides foundational contracts that facilitate a structured, extensible, and maintainable Minimal API architecture.

✅ Key Abstractions

  • 📐 Activators

    • IActivator
    • IAsyncActivator<T>
    • ICustomActivator<T>
  • 📦 JSON Serialization & Differencing

    • IJsonSerializer for robust serialization and deserialization.
    • IJsonDiffer for detailed JSON comparison and difference detection.
  • ✔️ Advanced Validation

    • IAttributeValidator for recursive and attribute-driven validation.

    • CustomValidatorBase<T, TAttribute> for custom synchronous validation logic.

    • AsyncCustomValidatorBase<T, TAttribute> for asynchronous custom validation.

    • Request validation abstractions:

      • RequestValidator<TRequest> and AsyncRequestValidator<TRequest> for complete object validation.
      • PatchRequestValidator<TRequest> and AsyncPatchRequestValidator<TRequest> specifically tailored for PATCH scenarios.

📦 Installation

Using the .NET CLI

dotnet add package Siemens.AspNet.MinimalApi.Sdk.Contracts

⚡ Examples

Activator Usage

public class ExampleService
{
    private readonly IActivator _activator;

    public ExampleService(IActivator activator)
    {
        _activator = activator;
    }

    public async Task<MyClass> CreateMyClassAsync()
    {
        return await _activator.CreateInstanceAsync<MyClass>();
    }
}

JSON Differ Example

public void CheckJsonDifferences(IJsonDiffer jsonDiffer)
{
    var differences = jsonDiffer.FindDifferences("{\"name\":\"John\"}", "{\"name\":\"Jane\"}");
    foreach (var diff in differences)
    {
        Console.WriteLine($"Property: {diff.MemberPath}, Difference: {diff.MismatchType}");
    }
}

Custom Validation

internal static class AddAlphaNumericValidatorExtension
{
    internal static void AddAlphaNumericValidator(this IServiceCollection services)
    {
        services.AddSingletonIfNotExists<ICustomValidator, AlphaNumericValidator>();
    }
}

public class AlphaNumericAttribute(params string[] sampleValues) : CustomValidationAttribute<AlphaNumericValidator>(string.Empty, sampleValues);

public sealed class AlphaNumericValidator : CustomValidatorBase<string, AlphaNumericAttribute>
{
    protected override IEnumerable<ValidationErrorDetailsBase> Validate(PropertyInfo propertyInfo,
                                                                        AlphaNumericAttribute attribute,
                                                                        string? source)
    {
        if (source == null)
        {
            yield break;
        }

        if (source.Any(ch => !char.IsLetterOrDigit(ch)))
        {
            var sampleValues = attribute.SampleValues.Any() ? attribute.SampleValues : ["sample123"];

            yield return new ValidationErrorDetailsBase
            {
                Errors = [$"{propertyInfo.Name} must be alphanumeric."],
                Samples = sampleValues
            };
        }
    }
}

Async Request Validator

In this sample the async validator is used to validate a CreateDeploymentRequest object. The validator checks for the presence of required properties and validates them using the IAttributeValidator interface.

public sealed record CreateDeploymentRequest
{
    [ValidEnum]
    public required Stage Stage { get; init; }
};
internal static class AddCreateDeploymentRequestValidatorExtension
{
    internal static void AddCreateDeploymentRequestValidator(this IServiceCollection services)
    {
        services.AddSingletonIfNotExists<CreateDeploymentRequestValidator>();
    }
}

internal sealed class CreateDeploymentRequestValidator(IAttributeValidator attributeValidator) : AsyncRequestValidator<CreateDeploymentRequest>
{
    protected override async IAsyncEnumerable<PropertyValidationResult> GetValidationErrorsAsync(CreateDeploymentRequest request,
                                                                                                    [EnumeratorCancellation] CancellationToken cancellationToken = default)
    {
        var errors = await attributeValidator.ValidateAsync(request, cancellationToken).ConfigureAwait(false);
        foreach (var propertyValidationResult in errors)
        {
            yield return propertyValidationResult;
        }
    }
}

📌 Usage & Best Practices

  • Leverage IActivator for instance creation with dependency injection.
  • Leverage IAsyncActivator for instance creation with dependency injection in asynchronous contexts.
  • Utilize IJsonDiffer for tracking JSON changes in PATCH requests.
  • Implement custom validation logic by extending provided base validator classes.
  • Implement IAttributeValidator custom for attribute-driven validation scenarios.
  • Simplified attribut-based validation by the IAttributeValidator interface.

📚 Documentation

Additional details and examples are available in the repository documentation and upcoming online resources.


📢 Contributing

Your contributions and feedback are welcomed! Please create issues or pull requests to enhance this package.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  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.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Siemens.AspNet.MinimalApi.Sdk.Contracts:

Package Downloads
Siemens.AspNet.MinimalApi.Sdk

A library which contains following functions: - Siemens.AspNet.MinimalApi.Sdk

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.0-alpha.260 0 8/22/2025
0.1.0-alpha.259 0 8/22/2025
0.1.0-alpha.258 9 8/19/2025
0.1.0-alpha.257 14 8/18/2025
0.1.0-alpha.246 89 8/14/2025
0.1.0-alpha.245 90 8/14/2025
0.1.0-alpha.244 95 8/14/2025
0.1.0-alpha.243 89 8/14/2025
0.1.0-alpha.238 91 8/12/2025
0.1.0-alpha.237 264 8/6/2025
0.1.0-alpha.236 217 8/5/2025
0.1.0-alpha.235 188 8/5/2025
0.1.0-alpha.234 188 8/5/2025
0.1.0-alpha.233 156 8/4/2025
0.1.0-alpha.232 169 8/4/2025
0.1.0-alpha.231 64 8/1/2025
0.1.0-alpha.230 63 8/1/2025
0.1.0-alpha.229 87 7/31/2025
0.1.0-alpha.228 85 7/31/2025
0.1.0-alpha.227 88 7/31/2025
0.1.0-alpha.225 84 7/31/2025
0.1.0-alpha.224 88 7/30/2025
0.1.0-alpha.222 180 7/16/2025
0.1.0-alpha.219 157 7/14/2025
0.1.0-alpha.217 82 7/11/2025
0.1.0-alpha.212 160 7/8/2025
0.1.0-alpha.211 135 7/3/2025
0.1.0-alpha.207 109 7/3/2025
0.1.0-alpha.206 289 6/30/2025
0.1.0-alpha.205 89 6/27/2025
0.1.0-alpha.202 91 6/27/2025
0.1.0-alpha.200 88 6/27/2025
0.1.0-alpha.198 92 6/27/2025
0.1.0-alpha.196 91 6/27/2025
0.1.0-alpha.195 94 6/27/2025
0.1.0-alpha.194 87 6/27/2025
0.1.0-alpha.193 92 6/27/2025
0.1.0-alpha.192 92 6/27/2025
0.1.0-alpha.191 89 6/27/2025
0.1.0-alpha.189 111 6/26/2025
0.1.0-alpha.188 166 6/26/2025
0.1.0-alpha.187 106 6/26/2025
0.1.0-alpha.186 129 6/26/2025
0.1.0-alpha.185 114 6/26/2025
0.1.0-alpha.184 116 6/26/2025
0.1.0-alpha.183 113 6/26/2025
0.1.0-alpha.182 111 6/26/2025
0.1.0-alpha.181 125 6/25/2025
0.1.0-alpha.180 119 6/24/2025
0.1.0-alpha.179 110 6/23/2025
0.1.0-alpha.178 196 6/23/2025
0.1.0-alpha.176 117 6/23/2025
0.1.0-alpha.174 118 6/19/2025
0.1.0-alpha.173 155 6/19/2025
0.1.0-alpha.172 116 6/17/2025
0.1.0-alpha.171 194 6/16/2025
0.1.0-alpha.169 112 6/16/2025
0.1.0-alpha.165 295 6/13/2025
0.1.0-alpha.164 226 6/13/2025
0.1.0-alpha.163 225 6/13/2025
0.1.0-alpha.160 261 6/12/2025
0.1.0-alpha.159 356 6/11/2025
0.1.0-alpha.158 264 6/11/2025
0.1.0-alpha.143 257 6/11/2025
0.1.0-alpha.142 259 6/11/2025
0.1.0-alpha.140 261 6/11/2025
0.1.0-alpha.139 314 6/10/2025
0.1.0-alpha.138 251 6/9/2025
0.1.0-alpha.137 48 6/7/2025
0.1.0-alpha.136 43 6/7/2025
0.1.0-alpha.135 78 6/6/2025
0.1.0-alpha.134 77 6/6/2025
0.1.0-alpha.130 124 6/5/2025
0.1.0-alpha.129 116 6/4/2025
0.1.0-alpha.128 112 6/4/2025
0.1.0-alpha.122 181 6/3/2025
0.1.0-alpha.121 128 6/1/2025
0.1.0-alpha.120 83 6/1/2025
0.1.0-alpha.118 126 5/28/2025
0.1.0-alpha.117 122 5/28/2025
0.1.0-alpha.116 150 5/28/2025
0.1.0-alpha.115 125 5/26/2025
0.1.0-alpha.114 154 5/22/2025
0.1.0-alpha.112 121 5/21/2025
0.1.0-alpha.111 117 5/20/2025
0.1.0-alpha.108 178 5/19/2025
0.1.0-alpha.104 475 5/18/2025
0.1.0-alpha.102 351 5/14/2025
0.1.0-alpha.101 202 5/14/2025
0.1.0-alpha.100 207 5/12/2025
0.1.0-alpha.99 233 5/12/2025
0.1.0-alpha.98 53 5/10/2025
0.1.0-alpha.97 45 5/10/2025
0.1.0-alpha.86 145 5/8/2025
0.1.0-alpha.85 116 5/8/2025
0.1.0-alpha.84 119 5/8/2025
0.1.0-alpha.82 134 5/7/2025
0.1.0-alpha.81 122 5/6/2025