eQuantic.Core.Application 1.6.23

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

// Install eQuantic.Core.Application as a Cake Tool
#tool nuget:?package=eQuantic.Core.Application&version=1.6.23                

eQuantic.Core.Api Library

The eQuantic Core API provides all the implementation needed to publish standard APIs.

To install eQuantic.Core.Api, run the following command in the Package Manager Console

Install-Package eQuantic.Core.Api

Example of implementation

The data entities

[Table("orders")]
public class OrderData : EntityDataBase
{
    [Key]
    public string Id { get; set; } = string.Empty;
    public DateTime Date { get; set; }
    
    public virtual ICollection<OrderItemData> Items { get; set; } = new HashSet<OrderItemData>();
}

[Table("orderItems")]
public class OrderItemData : EntityDataBase, IWithReferenceId<OrderItemData, int>
{
    [Key]
    public int Id { get; set; }
    public int OrderId { get; set; }
    
    [ForeignKey(nameof(OrderId))]
    public virtual OrderData? Order { get; set; }
    
    [Required]
    [MaxLength(200)]
    public string Name { get; set; } = string.Empty;
}

The models

public class Order
{
    public string Id { get; set; } = string.Empty;
    public DateTime Date { get; set; }
}

public class OrderItem
{
    public int Id { get; set; }
    public int OrderId { get; set; }
    public string Name { get; set; } = string.Empty;
}

The request models

public class OrderRequest
{
    public DateTime? Date { get; set; }
}

public class OrderItemRequest
{
    public string? Name { get; set; }
}

The mappers

public class OrderMapper : IMapper<OrderData, Order>, IMapper<OrderRequest, OrderData>
{
    public Order? Map(OrderData? source)
    {
        return Map(source, new Order());
    }

    public Order? Map(OrderData? source, Order? destination)
    {
        if (source == null)
        {
            return null;
        }

        if (destination == null)
        {
            return Map(source);
        }

        destination.Id = source.Id;
        destination.Date = source.Date;

        return destination;
    }

    public OrderData? Map(OrderRequest? source)
    {
        return Map(source, new OrderData());
    }

    public OrderData? Map(OrderRequest? source, OrderData? destination)
    {
        if (source == null)
        {
            return null;
        }

        if (destination == null)
        {
            return Map(source);
        }
        
        destination.Date = source.Date ?? DateTime.UtcNow;

        return destination;
    }
}

The services

public interface IOrderService : IApplicationService
{
    
}

[MapCrudEndpoints]
public class OrderService : IOrderService
{
    private readonly IMapperFactory _mapperFactory;
    private readonly ILogger<ExampleService> _logger;
    private readonly IAsyncQueryableRepository<IQueryableUnitOfWork, OrderData, int> _repository;
    
    public OrderService(
        IApplicationContext<int> applicationContext,
        IQueryableUnitOfWork unitOfWork, 
        IMapperFactory mapperFactory, 
        ILogger<OrderService> logger)
    {
        _mapperFactory = mapperFactory;
        _logger = logger;
        _repository = unitOfWork.GetAsyncQueryableRepository<IQueryableUnitOfWork, OrderData, int>();
    }
    
    public async Task<Order?> GetByIdAsync(int orderId, CancellationToken cancellationToken = default)
    {
        var item = await _repository.GetAsync(orderId, cancellationToken: cancellationToken);

        if (item == null)
        {
            var ex = new EntityNotFoundException<int>(orderId);
            _logger.LogError(ex, "{ServiceName} - GetById: Entity of {EntityName} not found", GetType().Name,
                nameof(OrderData));
            throw ex;
        }

        var mapper = _mapperFactory.GetMapper<OrderData, Order>()!;
        var result = mapper.Map(item);
        
        return result;
    }
}

The Program.cs

var builder = WebApplication.CreateBuilder(args);
var assembly = typeof(Program).Assembly;

builder.Services.AddDbContext<ExampleDbContext>(opt =>
    opt.UseInMemoryDatabase("ExampleDb"));
        
builder.Services.AddQueryableRepositories<ExampleUnitOfWork>(opt =>
{
    opt.FromAssembly(assembly)
        .AddLifetime(ServiceLifetime.Scoped);
});

builder.Services
    .AddMappers(opt => opt.FromAssembly(assembly))
    .AddTransient<IExampleService, ExampleService>()
    .AddControllers()
    .AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
        options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
    })
    .AddFilterModelBinder()
    .AddSortModelBinder();

builder.Services
    .AddEndpointsApiExplorer()
    .AddApiDocumentation(opt => opt.WithTitle("Example API"));

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseApiDocumentation();
}

app.UseHttpsRedirection();
app.UseRouting();
app.MapControllers();
app.MapGet("orders/{id}", GetById);

app.Run();
return;

async Task<Results<Ok<Order>, NotFound>> GetById(
    [FromRoute] int id, 
    [FromServices] IOrderService service, 
    CancellationToken cancellationToken)
{
    var item = await service.GetByIdAsync(id, cancellationToken);
    if (item == null)
        return TypedResults.NotFound();

    return TypedResults.Ok(item);
}

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  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 is compatible.  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. 
.NET Core netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.1 is compatible. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on eQuantic.Core.Application:

Package Downloads
eQuantic.Core.Application.Crud

eQuantic Application CRUD Library

eQuantic.Core.Api

eQuantic API Library

eQuantic.Core.Persistence

eQuantic Persistence Library

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.7.9 229 10/11/2024
1.7.8 222 10/4/2024
1.7.7 176 10/4/2024
1.7.6 179 10/3/2024
1.7.5 370 9/4/2024
1.7.4 271 9/1/2024
1.7.3 210 8/25/2024
1.7.2 326 7/29/2024
1.7.1 139 7/28/2024
1.7.0 103 7/28/2024
1.6.25 126 7/27/2024
1.6.24 283 7/22/2024
1.6.23 352 6/23/2024
1.6.22 142 6/23/2024
1.6.21 179 6/22/2024
1.6.20 133 6/21/2024
1.6.19 431 5/18/2024
1.6.18 369 5/4/2024
1.6.17 545 4/11/2024
1.6.16 182 4/11/2024
1.6.15 174 4/9/2024
1.6.14 193 4/4/2024
1.6.13 234 4/2/2024
1.6.12 239 3/21/2024
1.6.11 194 3/21/2024
1.6.10 246 3/18/2024
1.6.9 204 3/10/2024
1.6.8 212 2/18/2024
1.6.7 177 2/17/2024
1.6.6 201 2/14/2024
1.6.5 201 2/13/2024
1.6.4 202 2/12/2024
1.6.3 200 2/10/2024
1.6.2 179 2/10/2024
1.6.1 189 1/22/2024
1.6.0 364 12/21/2023
1.5.2 236 12/10/2023
1.5.1 207 12/5/2023
1.5.0 205 12/5/2023
1.4.0 211 12/3/2023
1.3.3 251 11/18/2023
1.3.2 198 11/18/2023
1.3.1 232 11/15/2023
1.3.0 192 11/15/2023
1.2.3 219 11/2/2023
1.2.2 178 11/2/2023
1.2.1 261 10/21/2023
1.2.0 172 10/21/2023
1.1.6 204 10/9/2023
1.1.5 208 10/7/2023
1.1.4 235 10/2/2023
1.1.3 197 10/1/2023
1.1.2 227 9/25/2023
1.1.1 173 9/24/2023
1.1.0 256 9/4/2023
1.0.14 354 8/13/2023
1.0.13 240 8/13/2023
1.0.12 215 8/13/2023
1.0.11 221 8/13/2023
1.0.10 217 8/8/2023
1.0.9 251 8/3/2023
1.0.8 236 7/30/2023
1.0.7 240 7/22/2023
1.0.6 238 7/21/2023
1.0.5 229 7/21/2023
1.0.4 220 7/20/2023
1.0.3 220 7/20/2023
1.0.2 217 7/19/2023
1.0.0.1 216 7/5/2023
1.0.0 223 7/5/2023

Conventions for Application Layer