Rystem.RepositoryFramework.Api.Server 5.0.18

There is a newer version of this package available.
See the version list below for details.
dotnet add package Rystem.RepositoryFramework.Api.Server --version 5.0.18                
NuGet\Install-Package Rystem.RepositoryFramework.Api.Server -Version 5.0.18                
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="Rystem.RepositoryFramework.Api.Server" Version="5.0.18" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rystem.RepositoryFramework.Api.Server --version 5.0.18                
#r "nuget: Rystem.RepositoryFramework.Api.Server, 5.0.18"                
#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.
// Install Rystem.RepositoryFramework.Api.Server as a Cake Addin
#addin nuget:?package=Rystem.RepositoryFramework.Api.Server&version=5.0.18

// Install Rystem.RepositoryFramework.Api.Server as a Cake Tool
#tool nuget:?package=Rystem.RepositoryFramework.Api.Server&version=5.0.18                

What is Rystem?

Api auto-generated

In your web application you have only to add one row after service build.

 services.AddApiFromRepositoryFramework()
    .WithDescriptiveName("Repository Api")
    .WithPath(Path)
    .WithSwagger()
    .WithVersion(Version)
    .WithDocumentation()
    .WithDefaultCors("http://example.com");

var app = builder.Build();
app.UseApiFromRepositoryFramework()
   .WithNoAuthorization();

public static ApiAuthorizationBuilder UseApiFromRepositoryFramework<TEndpointRouteBuilder>(
    this TEndpointRouteBuilder app,
    string startingPath = "api")
    where TEndpointRouteBuilder : IEndpointRouteBuilder

You may add api for each service by

public static ApiAuthorizationBuilder UseApiForRepository<T>(this IEndpointRouteBuilder app,
    string startingPath = "api")

Startup example

In the example below you may find the setup of three populated repositories, two of them are of the same kind (SuperUser). The SuperiorUser will be added to the app but will be not exposed as Api cause the SetNotExposable() method. Futhermore, we are adding a configuration for AAD to implement authentication on api.

var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddRepository<SuperUser, string>(settins =>
{
    settins.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(120, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com");
    });
    settins.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(2, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com");
    }, "inmemory");
});

builder.Services.AddRepository<SuperiorUser, string>(settings =>
{
    settings.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(120, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com")
            .WithPattern(x => x.Value!.Port, @"[1-9]{3,4}");
    });
    settings.SetNotExposable();
});
    
builder.Services.AddApiFromRepositoryFramework()
    .WithDescriptiveName("Repository Api")
    .WithPath(Path)
    .WithSwagger()
    .WithVersion(Version)
    .WithDocumentation()
    .WithDefaultCors("http://example.com");  

var app = builder.Build();
await app.Services.WarmUpAsync();

app.UseHttpsRedirection();
app.UseApiFromRepositoryFramework()
    .WithDefaultAuthorization();
app.Run();

No Authorization flow - default

var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddRepository<SuperUser, string>(settins =>
{
    settins.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(120, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com");
    });
    settins.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(2, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com");
    }, "inmemory");
});

builder.Services.AddRepository<SuperiorUser, string>(settings =>
{
    settings.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(120, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com")
            .WithPattern(x => x.Value!.Port, @"[1-9]{3,4}");
    });
    settings.SetNotExposable();
});
builder.Services.AddApiFromRepositoryFramework()
    .WithDescriptiveName("Repository Api")
    .WithPath(Path)
    .WithSwagger()
    .WithVersion(Version)
    .WithDocumentation()
    .WithDefaultCors("http://example.com");    

var app = builder.Build();
await app.Services.WarmUpAsync();
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseHttpsRedirection();
app.UseApiFromRepositoryFramework()
    .WithNoAuthorization();
app.Run();

Authorization flow - custom policies

You may configure the scoper for each method of your repository and for each repository, as you wish.

var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddRepository<SuperUser, string>(settins =>
{
    settins.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(120, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com");
    });
    settins.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(2, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com");
    }, "inmemory");
});

builder.Services.AddRepository<SuperiorUser, string>(settings =>
{
    settings.WithInMemory(builder =>
    {
        builder
            .PopulateWithRandomData(120, 5)
            .WithPattern(x => x.Value!.Email, @"[a-z]{5,10}@gmail\.com")
            .WithPattern(x => x.Value!.Port, @"[1-9]{3,4}");
    });
    settings.SetNotExposable();
});

builder.Services.AddAuthorization(
    options =>
    {
        options.AddPolicy("NormalUser", x =>
        {
            x.RequireClaim(ClaimTypes.Name);
        });
        options.AddPolicy("SuperAdmin", x =>
        {
            x.RequireRole("SuperAdmin");
        });
    });

builder.Services.AddApiFromRepositoryFramework()
    .WithDescriptiveName("Repository Api")
    .WithPath(Path)
    .WithSwagger()
    .WithVersion(Version)
    .WithDocumentation()
    .WithDefaultCors("http://example.com");     

var app = builder.Build();
await app.Services.WarmUpAsync();
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}
app.UseHttpsRedirection();

app.UseEndpoints(endpoints =>
{
    endpoints.MapHealthChecks("/healthz");
    endpoints.UseApiFromRepository<SuperUser>()
        .SetPolicyForCommand()
        .With("SuperAdmin")
        .Build();
    endpoints.UseApiFromRepositoryFramework()
        .SetPolicyForAll()
        .With("NormalUser")
        .And()
        .SetPolicy(RepositoryMethods.Insert)
        .With("SuperAdmin")
        .And()
        .SetPolicy(RepositoryMethods.Update)
        .With("SuperAdmin")
        .Build();
    endpoints
        .MapControllers();
});
app.Run();

In this example, I'm configuring a policy named "NormalUser" for all methods and all repositories, and a policy named "SuperAdmin" for the methods Insert and Update for all repositories and for the command (Insert, Updated and Delete) of SuperUser repository. You can customize it repository for repository, using UseApiFromRepository<T>() method.

Sample of filter usage when you use the api directly

All the requests are basic requests, the strangest request is only the query and you must use the Linq query. You may find some examples down below:

ƒ => (((ƒ.X == "dasda") AndAlso ƒ.X.Contains("dasda")) AndAlso ((ƒ.E == Guid.Parse("bf46510b-b7e6-4ba2-88da-cef208aa81f2")) Or (ƒ.Id == 32)))
ƒ => ((((ƒ.X == "dasda") AndAlso ƒ.Sol) AndAlso ƒ.X.Contains("dasda")) AndAlso ((ƒ.E == Guid.Parse("bf46510b-b7e6-4ba2-88da-cef208aa81f2")) Or (ƒ.Id == 32)))
ƒ => (((((ƒ.X == "dasda") AndAlso ƒ.Sol) AndAlso ƒ.X.Contains("dasda")) AndAlso ((ƒ.E == Guid.Parse("bf46510b-b7e6-4ba2-88da-cef208aa81f2")) Or (ƒ.Id == 32))) AndAlso ((ƒ.Type == 1) OrElse (ƒ.Type == 2)))
ƒ => (ƒ.Type == 2)
ƒ => (((((ƒ.X == "dasda") AndAlso ƒ.Sol) AndAlso (ƒ.X.Contains("dasda") OrElse ƒ.Sol.Equals(True))) AndAlso ((ƒ.E == Guid.Parse("bf46510b-b7e6-4ba2-88da-cef208aa81f2")) Or (ƒ.Id == 32))) AndAlso ((ƒ.Type == 1) OrElse (ƒ.Type == 2)))
ƒ => ((((((ƒ.X == "dasda") AndAlso ƒ.Samules.Any(x => (x == "ccccde"))) AndAlso ƒ.Sol) AndAlso (ƒ.X.Contains("dasda") OrElse ƒ.Sol.Equals(True))) AndAlso ((ƒ.E == Guid.Parse("bf46510b-b7e6-4ba2-88da-cef208aa81f2")) Or (ƒ.Id == 32))) AndAlso ((ƒ.Type == 1) OrElse (ƒ.Type == 2)))
ƒ => (ƒ.ExpirationTime > Convert.ToDateTime("7/6/2022 9:48:56 AM"))
ƒ => (ƒ.TimeSpan > new TimeSpan(1000 as long))
ƒ => Not(ƒ.Inside.Inside.A.Equals("dasdad"))
ƒ => Not(String.IsNullOrWhiteSpace(ƒ.Inside.Inside.A))
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
9.0.0 12,279 11/16/2024
9.0.0-rc.1 74 10/18/2024
6.2.0 218,967 10/9/2024
6.1.1 95 10/9/2024
6.1.0 47,893 9/29/2024
6.0.24 134 9/11/2024
6.0.23 340,091 7/18/2024
6.0.21 115 6/18/2024
6.0.20 727,726 6/16/2024
6.0.19 30,347 6/14/2024
6.0.18 123 6/14/2024
6.0.17 101 6/14/2024
6.0.16 49,964 6/10/2024
6.0.15 114 6/9/2024
6.0.14 94,235 5/24/2024
6.0.13 136 5/23/2024
6.0.12 100 5/23/2024
6.0.11 113 5/20/2024
6.0.9 85 5/20/2024
6.0.7 80 5/18/2024
6.0.6 135 5/10/2024
6.0.5 131 5/10/2024
6.0.4 549,797 4/3/2024
6.0.3 1,208 3/25/2024
6.0.2 393,562 3/11/2024
6.0.0 1,171,150 11/21/2023
6.0.0-rc.6 111 10/25/2023
6.0.0-rc.5 84 10/25/2023
6.0.0-rc.4 80 10/23/2023
6.0.0-rc.3 69 10/19/2023
6.0.0-rc.2 82 10/18/2023
6.0.0-rc.1 76 10/16/2023
5.0.20 638,578 9/25/2023
5.0.19 924 9/10/2023
5.0.18 904 9/6/2023
5.0.17 886 9/6/2023
5.0.16 951 9/5/2023
5.0.15 894 9/5/2023
5.0.14 867 9/5/2023
5.0.13 865 9/1/2023
5.0.12 899 8/31/2023
5.0.11 871 8/30/2023
5.0.10 884 8/29/2023
5.0.9 904 8/24/2023
5.0.8 922 8/24/2023
5.0.7 450,395 8/23/2023
5.0.6 18,243 8/21/2023
5.0.5 5,064 8/21/2023
5.0.4 931 8/16/2023
5.0.3 213,310 8/2/2023
5.0.2 2,588 8/2/2023
5.0.1 12,382 8/1/2023
5.0.0 12,664 7/31/2023
4.1.26 141,440 7/20/2023
4.1.25 25,427 7/16/2023
4.1.24 398,510 6/13/2023
4.1.23 46,468 6/13/2023
4.1.22 130,281 5/30/2023
4.1.21 56,208 5/20/2023
4.1.20 405,391 4/19/2023
4.1.19 96,210 3/20/2023
4.1.18 1,100 3/20/2023
4.1.17 1,083 3/16/2023
4.1.16 1,088 3/16/2023
4.1.15 1,045 3/15/2023
4.1.14 1,631 3/9/2023
4.1.13 1,072 3/7/2023
4.1.12 1,273 2/10/2023
4.1.11 1,154 1/26/2023
4.1.10 1,141 1/22/2023
4.1.9 1,124 1/20/2023
4.1.8 1,092 1/18/2023
4.1.7 1,296 1/18/2023
4.1.6 1,158 1/17/2023
4.1.1 1,154 1/4/2023
4.1.0 1,208 1/1/2023
3.1.5 1,137 12/21/2022
3.1.3 1,170 12/12/2022
3.1.2 1,124 12/7/2022
3.1.1 1,125 12/7/2022
3.1.0 1,189 12/2/2022
3.0.29 1,169 12/1/2022
3.0.28 1,154 12/1/2022
3.0.27 1,354 11/23/2022
3.0.25 1,200 11/23/2022
3.0.24 1,182 11/18/2022
3.0.23 1,170 11/18/2022
3.0.22 1,215 11/15/2022
3.0.21 1,218 11/14/2022
3.0.20 1,199 11/13/2022
3.0.19 1,430 11/2/2022
3.0.18 1,201 11/2/2022
3.0.17 1,203 10/29/2022
3.0.16 1,217 10/29/2022
3.0.15 1,181 10/29/2022
3.0.14 1,288 10/24/2022
3.0.13 1,262 10/24/2022
3.0.12 1,292 10/17/2022
3.0.11 1,268 10/10/2022
3.0.10 1,296 10/6/2022
3.0.9 1,236 10/6/2022
3.0.8 1,218 10/6/2022
3.0.7 1,246 10/6/2022
3.0.6 1,218 10/5/2022
3.0.5 1,232 10/5/2022
3.0.4 1,196 10/5/2022
3.0.3 1,239 10/3/2022
3.0.2 1,242 9/30/2022
3.0.1 1,230 9/29/2022
2.0.17 1,244 9/29/2022
2.0.16 1,223 9/27/2022
2.0.15 1,339 9/27/2022
2.0.14 1,274 9/26/2022
2.0.13 1,311 9/26/2022
2.0.12 1,288 9/26/2022
2.0.11 1,229 9/25/2022
2.0.10 1,303 9/25/2022
2.0.9 1,308 9/22/2022
2.0.8 1,291 9/22/2022
2.0.6 1,242 9/20/2022
2.0.5 1,266 9/20/2022
2.0.4 1,260 9/20/2022
2.0.2 1,274 9/20/2022
2.0.1 1,359 9/13/2022
2.0.0 1,265 8/19/2022
1.1.24 1,295 7/30/2022
1.1.23 1,265 7/29/2022
1.1.22 1,259 7/29/2022
1.1.21 1,328 7/29/2022
1.1.20 1,292 7/29/2022
1.1.19 1,356 7/27/2022
1.1.17 1,250 7/27/2022
1.1.16 1,298 7/26/2022
1.1.15 1,316 7/25/2022
1.1.14 1,304 7/25/2022
1.1.13 1,252 7/22/2022
1.1.12 1,340 7/19/2022
1.1.11 1,318 7/19/2022
1.1.10 1,285 7/19/2022
1.1.9 1,298 7/19/2022
1.1.8 1,317 7/18/2022
1.1.7 1,294 7/18/2022
1.1.6 1,299 7/18/2022
1.1.5 1,282 7/17/2022
1.1.4 1,310 7/17/2022
1.1.3 1,320 7/17/2022
1.1.2 1,324 7/17/2022
1.1.0 1,313 7/17/2022
1.0.2 1,277 7/15/2022
1.0.1 1,246 7/15/2022
1.0.0 1,293 7/8/2022
0.10.7 1,315 7/7/2022
0.10.2 1,338 7/2/2022
0.10.1 1,261 7/1/2022
0.10.0 1,266 7/1/2022
0.9.11 1,311 6/29/2022
0.9.10 1,311 6/20/2022
0.9.9 1,274 6/11/2022
0.9.7 1,329 6/9/2022
0.9.6 1,280 6/5/2022
0.9.5 1,301 6/3/2022
0.9.4 1,292 6/3/2022
0.9.3 1,266 6/3/2022
0.9.2 1,280 5/31/2022
0.9.1 1,260 5/31/2022
0.9.0 1,260 5/31/2022