├── src ├── FastArchitecture.Domain │ ├── Abstractions │ │ ├── IAggregateRoot.cs │ │ └── Entity.cs │ ├── FastArchitecture.Domain.csproj │ └── Orders │ │ └── Order.cs ├── FastArchitecture.Api │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── Endpoints │ │ └── Orders │ │ │ ├── ConfirmOrderEndpoint.cs │ │ │ ├── GetOrdersEndpoint.cs │ │ │ ├── CreateDraftOrderEndpoint.cs │ │ │ ├── GetOrdersV1Endpoint.cs │ │ │ ├── GetCountryListEndpoint.cs │ │ │ ├── GetOrderByNameEndpoint.cs │ │ │ └── ConfirmAllOrdersEndpoint.cs │ ├── Properties │ │ └── launchSettings.json │ ├── FastArchitecture.Api.csproj │ ├── Program.cs │ └── Abstractions │ │ └── ApiEndpoints.cs ├── FastArchitecture.Handlers │ ├── Abstractions │ │ ├── IQuery.cs │ │ ├── IHandlerContext.cs │ │ ├── HandlerContext.cs │ │ ├── FunctionHandlerContext.cs │ │ ├── QueryHandler.cs │ │ ├── HandlerRequestContext.cs │ │ ├── CommandHandler.cs │ │ └── IHandlerResponse.cs │ ├── Orders │ │ ├── Queries │ │ │ ├── Models │ │ │ │ └── OrderListModel.cs │ │ │ ├── GetCountries.cs │ │ │ ├── GetOrders.cs │ │ │ └── GetOrderByName.cs │ │ └── Commands │ │ │ ├── ConfirmAllOrders.cs │ │ │ ├── CreateOrder.cs │ │ │ ├── ConfirmOrder.cs │ │ │ └── CreateDraftOrder.cs │ ├── FastArchitecture.Handlers.csproj │ └── Registration │ │ └── ServiceCollectionExtensions.cs ├── FastArchitecture.Core │ ├── Constants │ │ └── ConnectionStrings.cs │ └── FastArchitecture.Core.csproj ├── FastArchitecture.Functions │ ├── Properties │ │ ├── launchSettings.json │ │ ├── serviceDependencies.json │ │ └── serviceDependencies.local.json │ ├── host.json │ ├── Configuration │ │ └── JsonOptions.cs │ ├── CustomFastEndpoints │ │ └── DumbEndpoint.cs │ ├── ServiceBus │ │ └── OrderPaidFunction.cs │ ├── HttpTriggers │ │ └── ConfirmAllOrdersFunction.cs │ ├── Program.cs │ ├── FastArchitecture.Functions.csproj │ ├── Logging │ │ └── FunctionLog.cs │ ├── Abstractions │ │ └── FunctionBase.cs │ └── .gitignore └── FastArchitecture.Infrastructure │ ├── Persistence │ └── ApplicationDbContext.cs │ ├── Migrations │ ├── 20230714170507_InitialCreate.cs │ ├── ApplicationDbContextModelSnapshot.cs │ └── 20230714170507_InitialCreate.Designer.cs │ └── FastArchitecture.Infrastructure.csproj ├── tests └── FastArchitecture.UnitTests │ ├── Shared │ ├── LoggerFactory.cs │ └── InMemoryDbContextFactory.cs │ ├── Usings.cs │ ├── Factories │ └── HandlerContextFactory.cs │ ├── Domain │ └── OrderTests.cs │ ├── Handlers │ └── Orders │ │ ├── GetOrdersTest.cs │ │ ├── GetOrderByNameTests.cs │ │ ├── CreateDraftOrderTests.cs │ │ └── CreateOrderTests.cs │ └── FastArchitecture.UnitTests.csproj ├── README.md ├── .gitignore ├── FastArchitecture.sln └── LICENSE /src/FastArchitecture.Domain/Abstractions/IAggregateRoot.cs: -------------------------------------------------------------------------------- 1 | namespace FastArchitecture.Domain.Abstractions 2 | { 3 | public interface IAggregateRoot 4 | { } 5 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/IQuery.cs: -------------------------------------------------------------------------------- 1 | using FastEndpoints; 2 | 3 | namespace FastArchitecture.Handlers.Abstractions; 4 | 5 | public interface IQuery : ICommand 6 | { 7 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Domain/Abstractions/Entity.cs: -------------------------------------------------------------------------------- 1 | namespace FastArchitecture.Domain.Abstractions 2 | { 3 | public abstract class Entity 4 | { 5 | public Guid Id { get; private set; } 6 | } 7 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Information", 5 | "Microsoft.AspNetCore": "Warning" 6 | } 7 | }, 8 | "AllowedHosts": "*" 9 | } 10 | -------------------------------------------------------------------------------- /src/FastArchitecture.Core/Constants/ConnectionStrings.cs: -------------------------------------------------------------------------------- 1 | namespace FastArchitecture.Core.Constants; 2 | 3 | public static class ConnectionStrings 4 | { 5 | public const string Sqlite = "Data Source=C:\\fast-architecture.db"; 6 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "FastArchitecture.Functions": { 4 | "commandName": "Project", 5 | "commandLineArgs": "--port 7190", 6 | "launchBrowser": false 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/host.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "2.0", 3 | "logging": { 4 | "applicationInsights": { 5 | "samplingSettings": { 6 | "isEnabled": true, 7 | "excludedTypes": "Request" 8 | } 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/Properties/serviceDependencies.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "appInsights1": { 4 | "type": "appInsights" 5 | }, 6 | "storage1": { 7 | "type": "storage", 8 | "connectionId": "AzureWebJobsStorage" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/Properties/serviceDependencies.local.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "appInsights1": { 4 | "type": "appInsights.sdk" 5 | }, 6 | "storage1": { 7 | "type": "storage.emulator", 8 | "connectionId": "AzureWebJobsStorage" 9 | } 10 | } 11 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/IHandlerContext.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Infrastructure.Persistence; 2 | using Serilog; 3 | 4 | namespace FastArchitecture.Handlers.Abstractions; 5 | 6 | public interface IHandlerContext 7 | { 8 | IDbContext DbContext { get; } 9 | ILogger Logger { get; } 10 | IHandlerRequestContext RequestContext { get; } 11 | } -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Shared/LoggerFactory.cs: -------------------------------------------------------------------------------- 1 | namespace FastArchitecture.UnitTests.Shared; 2 | 3 | public static class LoggerFactory 4 | { 5 | public static ILogger Create() 6 | { 7 | var logger = new LoggerConfiguration() 8 | .CreateLogger(); 9 | 10 | Log.Logger ??= logger; 11 | 12 | return logger; 13 | } 14 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Domain/FastArchitecture.Domain.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Usings.cs: -------------------------------------------------------------------------------- 1 | global using FastArchitecture.Handlers.Abstractions; 2 | global using FastArchitecture.Handlers.Orders.Commands; 3 | global using FastArchitecture.Handlers.Orders.Queries; 4 | global using FastArchitecture.Infrastructure.Persistence; 5 | global using FastArchitecture.UnitTests.Factories; 6 | global using FastArchitecture.UnitTests.Shared; 7 | global using Microsoft.EntityFrameworkCore; 8 | global using Serilog; 9 | global using Xunit; 10 | -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Factories/HandlerContextFactory.cs: -------------------------------------------------------------------------------- 1 | namespace FastArchitecture.UnitTests.Factories; 2 | 3 | public static class HandlerContextFactory 4 | { 5 | public static IHandlerContext GetHandlerContext(ApplicationDbContext dbContext, string? userId = null, string? email = null) 6 | { 7 | return new HandlerContext(dbContext, new HandlerRequestContext( 8 | userId, 9 | email, 10 | "kw"), 11 | LoggerFactory.Create()); 12 | } 13 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Endpoints/Orders/ConfirmOrderEndpoint.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Orders.Commands; 2 | 3 | namespace FastArchitecture.Api.Endpoints.Orders; 4 | 5 | public class ConfirmOrderEndpoint : ApiEndpoint 6 | { 7 | public override void Configure() 8 | { 9 | Post("orders.confirm"); 10 | AllowAnonymous(); 11 | } 12 | 13 | public override async Task HandleAsync(ConfirmOrder.Command command, CancellationToken ct) => await SendAsync(command, ct); 14 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Endpoints/Orders/GetOrdersEndpoint.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Orders.Queries; 2 | 3 | namespace FastArchitecture.Api.Endpoints.Orders; 4 | 5 | public class GetOrdersEndpoint : ApiEndpoint 6 | { 7 | public override void Configure() 8 | { 9 | Get("orders.list"); 10 | AllowAnonymous(); 11 | ResponseCache(60); 12 | } 13 | 14 | public override async Task HandleAsync(GetOrders.Query query, CancellationToken ct) => await SendAsync(query, ct); 15 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Queries/Models/OrderListModel.cs: -------------------------------------------------------------------------------- 1 | namespace FastArchitecture.Handlers.Orders.Queries.Models; 2 | 3 | public sealed class OrderListModel 4 | { 5 | public string Name { get; private set; } 6 | public string Status { get; private set; } 7 | 8 | public OrderListModel(Domain.Order order) 9 | { 10 | Name = order.Name; 11 | Status = order.Status; 12 | } 13 | 14 | public static OrderListModel Create(Domain.Order order) 15 | { 16 | return new OrderListModel(order); 17 | } 18 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Endpoints/Orders/CreateDraftOrderEndpoint.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Orders.Commands; 2 | 3 | namespace FastArchitecture.Api.Endpoints.Orders; 4 | 5 | public class CreateDraftOrderEndpoint : ApiEndpoint 6 | { 7 | public override void Configure() 8 | { 9 | Post("orders.create"); 10 | AllowAnonymous(); 11 | } 12 | 13 | public override async Task HandleAsync(CreateDraftOrder.Command command, CancellationToken ct) => await SendAsync(command, ct); 14 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Endpoints/Orders/GetOrdersV1Endpoint.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Orders.Queries; 2 | 3 | namespace FastArchitecture.Api.Endpoints.Orders; 4 | 5 | public class GetOrdersV1Endpoint : ApiEndpoint 6 | { 7 | public override void Configure() 8 | { 9 | Get("orders.list"); // /v1/orders.list 10 | AllowAnonymous(); 11 | Version(1); 12 | } 13 | 14 | public override async Task HandleAsync(GetOrders.Query query, CancellationToken ct) => await SendAsync(query, ct); 15 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Endpoints/Orders/GetCountryListEndpoint.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Orders.Queries; 2 | 3 | namespace FastArchitecture.Api.Endpoints.Orders; 4 | 5 | public class GetCountryListEndpoint : ApiEndpoint 6 | { 7 | public override void Configure() 8 | { 9 | Get("country.list"); 10 | AllowAnonymous(); 11 | ResponseCache(60); 12 | } 13 | 14 | public override async Task HandleAsync(GetCountries.Query query, CancellationToken ct) => await SendAsync(query, ct); 15 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > :warning: 2 | > I will no longer maintain this because I came out with something better 👇 👇 👇 3 | 4 | # Please check [Astro Architecture](https://github.com/kedzior-io/astro-architecture) 5 | 6 | I completely removed the dependency on FastEndpoints and focused on Minimal API 7 | 8 | 9 | # ~~Fast Architecture Solution Template .NET7~~ 10 | 11 | ~~This is a solution template for creating ASP.NET Core Web API that uses [FastEndpoints](https://fast-endpoints.com) and its command bus to get close to CQRS pattern with DDD (Domain Driven Design) design approach.~~ 12 | 13 | -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Endpoints/Orders/GetOrderByNameEndpoint.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Orders.Queries; 2 | using Microsoft.AspNetCore.Mvc; 3 | 4 | namespace FastArchitecture.Api.Endpoints.Orders; 5 | 6 | public class GetOrderByNameEndpoint : ApiEndpoint 7 | { 8 | public override void Configure() 9 | { 10 | Get("orders.getByName"); 11 | AllowAnonymous(); 12 | } 13 | 14 | public override async Task HandleAsync([FromQuery] GetOrderByName.Query query, CancellationToken ct) => await SendAsync(query, ct); 15 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/Configuration/JsonOptions.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json; 2 | using System.Text.Json.Serialization; 3 | 4 | namespace FastArchitecture.Functions.Configuration; 5 | 6 | public static class JsonOptions 7 | { 8 | public static readonly JsonSerializerOptions Defaults = new() 9 | { 10 | DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull, 11 | PropertyNamingPolicy = JsonNamingPolicy.CamelCase, 12 | PropertyNameCaseInsensitive = true, 13 | NumberHandling = JsonNumberHandling.AllowReadingFromString, 14 | WriteIndented = true, 15 | }; 16 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/CustomFastEndpoints/DumbEndpoint.cs: -------------------------------------------------------------------------------- 1 | using FastEndpoints; 2 | 3 | namespace FastArchitecture.Functions.CustomFastEndpoints; 4 | 5 | /// 6 | /// That's a workaround gor having commands triggered from azure functions using FastEndpoints 7 | /// 8 | public record Dumb(); 9 | 10 | public class DumbEndpoint : Endpoint 11 | { 12 | public override void Configure() 13 | { 14 | Post("dumb"); 15 | AllowAnonymous(); 16 | } 17 | 18 | public async Task HandleAsync(CancellationToken ct) 19 | { 20 | await SendEmptyJsonObject(ct); 21 | } 22 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/FastArchitecture.Handlers.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Shared/InMemoryDbContextFactory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Diagnostics; 2 | 3 | namespace FastArchitecture.UnitTests.Shared; 4 | 5 | public static class InMemoryDbContextFactory 6 | { 7 | public static ApplicationDbContext Create() 8 | { 9 | var _contextOptions = new DbContextOptionsBuilder() 10 | .UseInMemoryDatabase(Guid.NewGuid().ToString()) 11 | .ConfigureWarnings(b => b.Ignore(InMemoryEventId.TransactionIgnoredWarning)) 12 | .Options; 13 | 14 | return new ApplicationDbContext(_contextOptions); 15 | } 16 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Core/FastArchitecture.Core.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Endpoints/Orders/ConfirmAllOrdersEndpoint.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Orders.Commands; 2 | 3 | namespace FastArchitecture.Api.Endpoints.Orders; 4 | 5 | 6 | /* 7 | Using ApiEndpoint works if a valid empty json body is sent aka {} or null otherwise the endpoint will return status code 415 8 | If empty body post is needed to be sent it requires to inherit from ApiEndpointWithoutRequest 9 | */ 10 | public class ConfirmAllOrdersEndpoint : ApiEndpointWithoutRequest 11 | { 12 | public override void Configure() 13 | { 14 | Post("orders.confirm.all"); 15 | AllowAnonymous(); 16 | } 17 | 18 | public override async Task HandleAsync(CancellationToken ct) => await SendAsync(ct); 19 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/HandlerContext.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Infrastructure.Persistence; 2 | 3 | namespace FastArchitecture.Handlers.Abstractions; 4 | 5 | /* 6 | * TODO 1: Inject HostEnvironment 7 | */ 8 | 9 | public sealed class HandlerContext : IHandlerContext 10 | { 11 | public IDbContext DbContext { get; private set; } 12 | 13 | public IHandlerRequestContext RequestContext { get; private set; } 14 | 15 | public Serilog.ILogger Logger { get; private set; } 16 | 17 | public HandlerContext(IDbContext dbContext, IHandlerRequestContext requestContext, Serilog.ILogger logger/*, IHostEnvironment hostingEnvironment*/) 18 | { 19 | DbContext = dbContext; 20 | RequestContext = requestContext; 21 | Logger = logger; 22 | } 23 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/ServiceBus/OrderPaidFunction.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Functions.Abstractions; 2 | using FastArchitecture.Handlers.Commands; 3 | using FluentValidation; 4 | using Microsoft.Azure.Functions.Worker; 5 | using Serilog; 6 | 7 | namespace FastArchitecture.Functions.ServiceBus; 8 | 9 | public class OrderPaidFunction : FunctionBase 10 | { 11 | public OrderPaidFunction(ILogger logger, IValidator validator) : base(logger, validator) 12 | { 13 | } 14 | 15 | [Function(nameof(OrderPaidFunction))] 16 | public async Task Run([ServiceBusTrigger("test-queue", Connection = "ConnectionStrings:ServiceBus")] string json, FunctionContext context) 17 | { 18 | await ExecuteAsync(json, context); 19 | } 20 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:44650", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "http": { 13 | "commandName": "Project", 14 | "dotnetRunMessages": true, 15 | "launchBrowser": true, 16 | "launchUrl": "/swagger", 17 | "applicationUrl": "http://localhost:5054", 18 | "environmentVariables": { 19 | "ASPNETCORE_ENVIRONMENT": "Development" 20 | } 21 | }, 22 | "IIS Express": { 23 | "commandName": "IISExpress", 24 | "launchBrowser": true, 25 | "launchUrl": "/swagger", 26 | "environmentVariables": { 27 | "ASPNETCORE_ENVIRONMENT": "Development" 28 | } 29 | } 30 | } 31 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/FunctionHandlerContext.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Infrastructure.Persistence; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace FastArchitecture.Handlers.Abstractions; 5 | 6 | public sealed class FunctionHandlerContext : IHandlerContext 7 | { 8 | private readonly IDbContextFactory _dbContextfactory; 9 | 10 | public IDbContext DbContext => _dbContextfactory.CreateDbContext(); 11 | 12 | public IHandlerRequestContext RequestContext { get; private set; } 13 | 14 | public Serilog.ILogger Logger { get; private set; } 15 | 16 | public FunctionHandlerContext(IDbContextFactory dbContextfactory, IHandlerRequestContext requestContext, Serilog.ILogger logger/*, IHostEnvironment hostingEnvironment*/) 17 | { 18 | _dbContextfactory = dbContextfactory; 19 | RequestContext = requestContext; 20 | Logger = logger; 21 | } 22 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Queries/GetCountries.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | 3 | namespace FastArchitecture.Handlers.Orders.Queries; 4 | 5 | public static class GetCountries 6 | { 7 | public sealed class Query : IQuery> 8 | { 9 | } 10 | 11 | public sealed class Response 12 | { 13 | public IReadOnlyCollection Countries { get; set; } = Array.Empty(); 14 | } 15 | 16 | public sealed class Handler : QueryHandler 17 | { 18 | public Handler(IHandlerContext context) : base(context) 19 | { 20 | } 21 | 22 | public override Task> ExecuteAsync(Query query, CancellationToken ct) 23 | { 24 | var someNonAsyncStuff = new Response() { Countries = new List { "Spain", "United Stated of America" } }; 25 | 26 | return SuccessAsync(someNonAsyncStuff); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Commands/ConfirmAllOrders.cs: -------------------------------------------------------------------------------- 1 | 2 | using FastArchitecture.Handlers.Abstractions; 3 | using FastEndpoints; 4 | using Microsoft.EntityFrameworkCore; 5 | 6 | namespace FastArchitecture.Handlers.Orders.Commands; 7 | 8 | public static class ConfirmAllOrders 9 | { 10 | public sealed class Command : ICommand 11 | { 12 | } 13 | 14 | public sealed class Handler : Abstractions.CommandHandler 15 | { 16 | public Handler(IHandlerContext context) : base(context) 17 | { 18 | } 19 | 20 | public override async Task ExecuteAsync(Command command, CancellationToken ct = default) 21 | { 22 | var orders = await DbContext 23 | .Orders 24 | .ToListAsync(ct); 25 | 26 | orders.ForEach(x => x.SetConfrimed()); 27 | 28 | await DbContext.SaveChangesAsync(ct); 29 | 30 | return Success(); 31 | } 32 | } 33 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/HttpTriggers/ConfirmAllOrdersFunction.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Functions.Abstractions; 2 | using FastArchitecture.Handlers.Orders.Commands; 3 | using Microsoft.Azure.Functions.Worker; 4 | using Microsoft.Azure.Functions.Worker.Http; 5 | using Serilog; 6 | 7 | namespace FastArchitecture.Functions.HttpTriggers; 8 | 9 | /// 10 | /// An example of typical function triggered by a Azure Logic App 11 | /// 12 | /// FunctionBase - takse care of logging, validation and triggering the command 13 | /// 14 | /// 15 | public class ConfirmAllOrdersFunction : FunctionBase 16 | { 17 | public ConfirmAllOrdersFunction(ILogger logger) : base(logger) 18 | { 19 | } 20 | 21 | [Function(nameof(ConfirmAllOrdersFunction))] 22 | public async Task Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post")] HttpRequestData req) 23 | { 24 | var command = new ConfirmAllOrders.Command(); 25 | 26 | await ExecuteAsync(command, req.FunctionContext); 27 | } 28 | } -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Domain/OrderTests.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Domain; 2 | 3 | namespace FastArchitecture.Handlers.Orders; 4 | 5 | public class OrderTests 6 | { 7 | private static readonly string NewOrderName = "#0003"; 8 | private static readonly string NewOrderStatus = "created"; 9 | private static readonly string NewOrderUserId = "1"; 10 | 11 | [Fact] 12 | public void CreateOrder_EmptyName_ThrowsException() 13 | { 14 | Assert.Throws(() => new Order(string.Empty, NewOrderStatus, NewOrderUserId)); 15 | } 16 | 17 | [Fact] 18 | public void CreateOrder_EmptyStatus_ThrowsException() 19 | { 20 | Assert.Throws(() => new Order(NewOrderName, string.Empty, NewOrderUserId)); 21 | } 22 | 23 | [Fact] 24 | public void CreateOrder_ValidParameters_ReturnsOrder() 25 | { 26 | var order = new Order(NewOrderName, NewOrderStatus, NewOrderUserId); 27 | 28 | Assert.NotNull(order); 29 | Assert.NotEmpty(order.Name); 30 | Assert.NotEmpty(order.Status); 31 | } 32 | } -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Handlers/Orders/GetOrdersTest.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Domain; 2 | 3 | namespace FastArchitecture.Handlers.Orders; 4 | 5 | public class GetOrdersTests 6 | { 7 | private static GetOrders.Handler GetHandler(ApplicationDbContext dbContext) 8 | { 9 | return new GetOrders.Handler(HandlerContextFactory.GetHandlerContext(dbContext)); 10 | } 11 | 12 | private static void SetTestData(ApplicationDbContext dc) 13 | { 14 | var orders = new List { 15 | Order.Create("#0001"), 16 | Order.Create("#0002") 17 | }; 18 | 19 | dc.Orders.AddRange(orders); 20 | dc.SaveChanges(); 21 | } 22 | 23 | [Fact] 24 | public async Task Get_Orders_ReturnList() 25 | { 26 | var dbc = InMemoryDbContextFactory.Create(); 27 | SetTestData(dbc); 28 | 29 | var query = new GetOrders.Query(); 30 | var expected = 2; 31 | 32 | var response = await GetHandler(dbc).ExecuteAsync(query, default); 33 | 34 | Assert.Equal(expected, response.Payload.Orders.Count); 35 | } 36 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Commands/CreateOrder.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | using FastEndpoints; 3 | using FluentValidation; 4 | 5 | namespace FastArchitecture.Handlers.Commands; 6 | 7 | public static class CreateOrder 8 | { 9 | public sealed class Command : ICommand 10 | { 11 | public string Name { get; set; } = ""; 12 | } 13 | 14 | public sealed class MyValidator : Validator 15 | { 16 | public MyValidator() 17 | { 18 | RuleFor(x => x.Name) 19 | .MinimumLength(1) 20 | .WithMessage("Order name is too short!"); 21 | } 22 | } 23 | 24 | public sealed class Handler : Abstractions.CommandHandler 25 | { 26 | public Handler(IHandlerContext context) : base(context) 27 | { 28 | } 29 | 30 | public override async Task ExecuteAsync(Command command, CancellationToken ct) 31 | { 32 | var order = Domain.Order.Create(command.Name); 33 | await DbContext.Orders.AddAsync(order, ct); 34 | await DbContext.SaveChangesAsync(ct); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/FastArchitecture.Api.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | all 14 | runtime; build; native; contentfiles; analyzers; buildtransitive 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /src/FastArchitecture.Infrastructure/Persistence/ApplicationDbContext.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Core.Constants; 2 | using FastArchitecture.Domain; 3 | using Microsoft.EntityFrameworkCore; 4 | using System.Runtime.CompilerServices; 5 | 6 | namespace FastArchitecture.Infrastructure.Persistence; 7 | 8 | public interface IDbContext : IDisposable 9 | { 10 | public DbSet Orders { get; set; } 11 | 12 | Task SaveChangesAsync(CancellationToken cancellationToken = default, [CallerMemberName] string? callerFunction = null, [CallerFilePath] string? callerFile = null); 13 | } 14 | 15 | public class ApplicationDbContext : DbContext, IDbContext 16 | { 17 | public DbSet Orders { get; set; } = null!; 18 | 19 | public ApplicationDbContext(DbContextOptions options) : base(options) 20 | { 21 | } 22 | 23 | protected override void OnConfiguring(DbContextOptionsBuilder options) => options.UseSqlite(ConnectionStrings.Sqlite); 24 | 25 | public async Task SaveChangesAsync(CancellationToken cancellationToken = default, [CallerMemberName] string? callerFunction = null, [CallerFilePath] string? callerFile = null) => 26 | await base.SaveChangesAsync(cancellationToken).ConfigureAwait(false); 27 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Queries/GetOrders.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | using FastArchitecture.Handlers.Orders.Queries.Models; 3 | using Microsoft.EntityFrameworkCore; 4 | 5 | namespace FastArchitecture.Handlers.Orders.Queries; 6 | 7 | public static class GetOrders 8 | { 9 | public sealed class Query : IQuery> 10 | { 11 | } 12 | 13 | public sealed class Response 14 | { 15 | public IReadOnlyCollection Orders { get; private set; } 16 | 17 | public Response(IReadOnlyCollection orders) 18 | { 19 | Orders = orders.Select(OrderListModel.Create).ToList(); 20 | } 21 | } 22 | 23 | public sealed class Handler : QueryHandler 24 | { 25 | public Handler(IHandlerContext context) : base(context) 26 | { 27 | } 28 | 29 | public override async Task> ExecuteAsync(Query query, CancellationToken ct) 30 | { 31 | var orders = await DbContext 32 | .Orders 33 | .ToListAsync(ct); 34 | 35 | return Success(new Response(orders)); 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/QueryHandler.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Infrastructure.Persistence; 2 | using FastEndpoints; 3 | 4 | namespace FastArchitecture.Handlers.Abstractions; 5 | 6 | public abstract class QueryHandler : ICommandHandler> 7 | where TQuery : IQuery> 8 | { 9 | protected readonly IDbContext DbContext; 10 | protected readonly IHandlerRequestContext RequestContext; 11 | 12 | protected QueryHandler(IHandlerContext context) 13 | { 14 | DbContext = context.DbContext; 15 | RequestContext = context.RequestContext; 16 | } 17 | 18 | public abstract Task> ExecuteAsync(TQuery query, CancellationToken ct = default); 19 | 20 | public IHandlerResponse Success(TResponse response) 21 | { 22 | return HandlerResponse.Create(response); 23 | } 24 | 25 | public Task> SuccessAsync(TResponse response) 26 | { 27 | return Task.FromResult(Success(response)); 28 | } 29 | 30 | public IHandlerResponse Error(string message, params object[] parameters) 31 | { 32 | return HandlerResponse.CreateError(message, parameters); 33 | } 34 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Infrastructure/Migrations/20230714170507_InitialCreate.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.EntityFrameworkCore.Migrations; 2 | 3 | #nullable disable 4 | 5 | namespace FastArchitecture.Infrastructure.Migrations 6 | { 7 | /// 8 | public partial class InitialCreate : Migration 9 | { 10 | /// 11 | protected override void Up(MigrationBuilder migrationBuilder) 12 | { 13 | migrationBuilder.CreateTable( 14 | name: "Orders", 15 | columns: table => new 16 | { 17 | Id = table.Column(type: "TEXT", nullable: false), 18 | Name = table.Column(type: "TEXT", nullable: false), 19 | Status = table.Column(type: "TEXT", nullable: false), 20 | UserId = table.Column(type: "TEXT", nullable: false) 21 | }, 22 | constraints: table => 23 | { 24 | table.PrimaryKey("PK_Orders", x => x.Id); 25 | }); 26 | } 27 | 28 | /// 29 | protected override void Down(MigrationBuilder migrationBuilder) 30 | { 31 | migrationBuilder.DropTable( 32 | name: "Orders"); 33 | } 34 | } 35 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/HandlerRequestContext.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Http; 2 | using System.Security.Claims; 3 | 4 | namespace FastArchitecture.Handlers.Abstractions; 5 | 6 | public interface IHandlerRequestContext 7 | { 8 | string? UserId { get; } 9 | string? Email { get; } 10 | string? LanguageCode { get; } 11 | } 12 | 13 | public sealed class HandlerRequestContext : IHandlerRequestContext 14 | { 15 | public string? UserId { get; private set; } 16 | public string? Email { get; private set; } 17 | public string? LanguageCode { get; private set; } 18 | 19 | public HandlerRequestContext(string? userId, string? email, string? languageCode) 20 | { 21 | UserId = userId; 22 | Email = email; 23 | LanguageCode = languageCode; 24 | } 25 | 26 | public HandlerRequestContext(IHttpContextAccessor accessor) 27 | { 28 | if (accessor.HttpContext is not null) 29 | { 30 | UserId = accessor.HttpContext.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; 31 | Email = accessor.HttpContext.User.FindFirst(ClaimTypes.Email)?.Value; 32 | } 33 | 34 | // TODO: add RequestCulture 35 | // LanguageCode = accessor.HttpContext.Features.Get()!.RequestCulture.Culture.TwoLetterISOLanguageName; 36 | } 37 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Infrastructure/FastArchitecture.Infrastructure.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | all 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/FastArchitecture.UnitTests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net7.0 5 | enable 6 | enable 7 | 8 | false 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | runtime; build; native; contentfiles; analyzers; buildtransitive 17 | all 18 | 19 | 20 | runtime; build; native; contentfiles; analyzers; buildtransitive 21 | all 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Commands/ConfirmOrder.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Domain; 2 | using FastArchitecture.Handlers.Abstractions; 3 | using FastEndpoints; 4 | using FluentValidation; 5 | using Microsoft.EntityFrameworkCore; 6 | 7 | namespace FastArchitecture.Handlers.Orders.Commands; 8 | 9 | public static class ConfirmOrder 10 | { 11 | public sealed class Command : ICommand 12 | { 13 | public string Name { get; set; } = ""; 14 | } 15 | 16 | public sealed class MyValidator : Validator 17 | { 18 | public MyValidator() 19 | { 20 | RuleFor(x => x.Name) 21 | .MinimumLength(5) 22 | .WithMessage("Order name is too short!"); 23 | } 24 | } 25 | 26 | public sealed class Handler : Abstractions.CommandHandler 27 | { 28 | public Handler(IHandlerContext context) : base(context) 29 | { 30 | } 31 | 32 | public override async Task ExecuteAsync(Command command, CancellationToken ct) 33 | { 34 | var order = await DbContext 35 | .Orders 36 | .Where(x=> x.Name == command.Name) 37 | .SingleAsync(ct); 38 | 39 | order.SetConfrimed(); 40 | 41 | await DbContext.SaveChangesAsync(ct); 42 | 43 | return Success(); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Domain/Orders/Order.cs: -------------------------------------------------------------------------------- 1 | using Ardalis.GuardClauses; 2 | using FastArchitecture.Domain.Abstractions; 3 | 4 | namespace FastArchitecture.Domain; 5 | 6 | public class Order : Entity, IAggregateRoot 7 | { 8 | public string Name { get; private set; } = null!; 9 | public string Status { get; private set; } = null!; 10 | public string UserId { get; private set; } = null!; 11 | 12 | private Order() 13 | { 14 | // EF 15 | } 16 | 17 | public Order(string name, string status, string userId) 18 | { 19 | Guard.Against.NullOrWhiteSpace(name); 20 | Guard.Against.NullOrWhiteSpace(status); 21 | Guard.Against.NullOrWhiteSpace(userId); 22 | 23 | Name = name; 24 | Status = status; 25 | UserId = userId; 26 | } 27 | 28 | public void UpdateStatus(string status) 29 | { 30 | Guard.Against.NullOrWhiteSpace(status); 31 | Status = status; 32 | } 33 | 34 | public void SetConfrimed() 35 | { 36 | Status = "confirmed"; 37 | } 38 | 39 | public static Order CreateDraft(string name) 40 | { 41 | return new Order(name, "draft", "1"); 42 | } 43 | 44 | public static Order Create(string name) 45 | { 46 | return new Order(name, "created", "1"); 47 | } 48 | 49 | public static Order Create(string name, string userId) 50 | { 51 | return new Order(name, "created", userId); 52 | } 53 | } -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Handlers/Orders/GetOrderByNameTests.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Domain; 2 | 3 | namespace FastArchitecture.Handlers.Orders; 4 | 5 | public class GetOrderByNameTests 6 | { 7 | private static readonly string OrderName1UserId = "chucknorris"; 8 | 9 | private static readonly string OrderName1 = "#0001"; 10 | private static readonly string OrderName2 = "#0002"; 11 | 12 | private static GetOrderByName.Handler GetHandler(ApplicationDbContext dbContext) 13 | { 14 | return new GetOrderByName.Handler(HandlerContextFactory.GetHandlerContext(dbContext, userId: OrderName1UserId)); 15 | } 16 | 17 | private static void SetTestData(ApplicationDbContext dc) 18 | { 19 | var orders = new List { 20 | Order.Create(OrderName1, OrderName1UserId), 21 | Order.Create(OrderName2, OrderName1UserId), 22 | }; 23 | 24 | dc.Orders.AddRange(orders); 25 | dc.SaveChanges(); 26 | } 27 | 28 | [Fact] 29 | public async Task Get_Order_ReturnSingleOrder() 30 | { 31 | var dc = InMemoryDbContextFactory.Create(); 32 | SetTestData(dc); 33 | 34 | var query = new GetOrderByName.Query() 35 | { 36 | Name = OrderName1 37 | }; 38 | 39 | var expected = OrderName1; 40 | 41 | var response = await GetHandler(dc).ExecuteAsync(query, default); 42 | 43 | Assert.Equal(expected, response.Payload.Name); 44 | } 45 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/CommandHandler.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Infrastructure.Persistence; 2 | using FastEndpoints; 3 | 4 | namespace FastArchitecture.Handlers.Abstractions; 5 | 6 | public abstract class CommandHandler : ICommandHandler> where TCommand : ICommand> 7 | { 8 | protected readonly IDbContext DbContext; 9 | 10 | protected CommandHandler(IHandlerContext context) 11 | { 12 | DbContext = context.DbContext; 13 | } 14 | 15 | public abstract Task> ExecuteAsync(TCommand command, CancellationToken ct = default); 16 | 17 | public IHandlerResponse Success(TResponse response) 18 | { 19 | return HandlerResponse.Create(response); 20 | } 21 | } 22 | 23 | public abstract class CommandHandler : ICommandHandler where TCommand : ICommand 24 | { 25 | protected readonly IDbContext DbContext; 26 | 27 | protected CommandHandler(IHandlerContext context) 28 | { 29 | DbContext = context.DbContext; 30 | } 31 | 32 | public abstract Task ExecuteAsync(TCommand command, CancellationToken ct = default); 33 | 34 | public IHandlerResponse Success() 35 | { 36 | return HandlerResponse.CreateEmpty(); 37 | } 38 | 39 | public IHandlerResponse Error(string error) 40 | { 41 | return HandlerResponse.CreateEmpty(); 42 | } 43 | } -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Handlers/Orders/CreateDraftOrderTests.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Domain; 2 | 3 | namespace FastArchitecture.Handlers.Orders; 4 | 5 | public class CreateDraftOrderTests 6 | { 7 | private static readonly string NewOrderName = "#0003"; 8 | private static readonly string NewOrderStatus = "draft"; 9 | 10 | private static CreateDraftOrder.Handler GetHandler(ApplicationDbContext dbContext) 11 | { 12 | return new CreateDraftOrder.Handler(HandlerContextFactory.GetHandlerContext(dbContext)); 13 | } 14 | 15 | private static void SetTestData(ApplicationDbContext dc) 16 | { 17 | var orders = new List { 18 | Order.CreateDraft("#0001"), 19 | Order.CreateDraft("#0002"), 20 | }; 21 | 22 | dc.Orders.AddRange(orders); 23 | dc.SaveChanges(); 24 | } 25 | 26 | [Fact] 27 | public async Task Create_DraftOrder_ReturnEmpty() 28 | { 29 | var dc = InMemoryDbContextFactory.Create(); 30 | 31 | SetTestData(dc); 32 | 33 | var command = new CreateDraftOrder.Command() 34 | { 35 | Name = NewOrderName 36 | }; 37 | 38 | var expectedName = NewOrderName; 39 | var expectedStatus = NewOrderStatus; 40 | 41 | await GetHandler(dc).ExecuteAsync(command, default); 42 | 43 | var result = dc.Orders.SingleOrDefault(o => o.Name == NewOrderName); 44 | 45 | Assert.NotNull(result); 46 | Assert.Equal(expectedName, result.Name); 47 | Assert.Equal(expectedStatus, result.Status); 48 | } 49 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/Program.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | using FastArchitecture.Handlers.Registration; 3 | using FastArchitecture.Infrastructure.Persistence; 4 | using FastEndpoints; 5 | using FluentValidation; 6 | using Microsoft.AspNetCore.Builder; 7 | using Microsoft.Extensions.DependencyInjection; 8 | using Microsoft.Extensions.Hosting; 9 | using Serilog; 10 | using Serilog.Events; 11 | 12 | /* 13 | * TODO 2: Avoid creating webAppBuilder (required to use FastEndpoints) 14 | */ 15 | 16 | var host = new HostBuilder() 17 | .ConfigureFunctionsWorkerDefaults() 18 | .ConfigureServices(s => 19 | { 20 | var loggerConfiguration = new LoggerConfiguration() 21 | .MinimumLevel.Debug() 22 | .MinimumLevel.Override("Microsoft", LogEventLevel.Information) 23 | .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning) 24 | .MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning) 25 | .Enrich.WithProperty("SourceLogger", "Serilog"); 26 | 27 | var logger = loggerConfiguration.CreateLogger(); 28 | 29 | s.AddSingleton(_ => logger); 30 | s.AddValidatorsFromAssemblyContaining(); 31 | 32 | var webAppBuilder = WebApplication.CreateBuilder(); 33 | 34 | webAppBuilder.Services.AddSingleton(_ => logger); 35 | webAppBuilder.Services.AddAzureFunctionsDependencies(); 36 | 37 | var app = webAppBuilder.Build(); 38 | 39 | app.UseFastEndpoints(); 40 | }) 41 | .Build(); 42 | 43 | host.Run(); -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Registration/ServiceCollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | using FastArchitecture.Infrastructure.Persistence; 3 | using FastEndpoints; 4 | using Microsoft.Extensions.DependencyInjection; 5 | 6 | namespace FastArchitecture.Handlers.Registration; 7 | 8 | public static class ServiceCollectionExtensions 9 | { 10 | public static IServiceCollection AddApiDependencies(this IServiceCollection services) 11 | { 12 | services.AddScoped(); 13 | 14 | services.AddCommonDependencies(); 15 | 16 | return services; 17 | } 18 | 19 | public static IServiceCollection AddAzureFunctionsDependencies(this IServiceCollection services) 20 | { 21 | services.AddScoped(); 22 | services.AddDbContextFactory(); 23 | 24 | services.AddCommonDependencies(); 25 | 26 | return services; 27 | } 28 | 29 | private static IServiceCollection AddCommonDependencies(this IServiceCollection services) 30 | { 31 | services.AddFastEndpoints(dicoveryOptions => 32 | { 33 | dicoveryOptions.Assemblies = new[] { typeof(Abstractions.CommandHandler<>).Assembly }; 34 | }); 35 | 36 | services.AddScoped(); 37 | services.AddDbContext(); 38 | services.AddScoped(provider => provider.GetRequiredService()); 39 | 40 | return services; 41 | } 42 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Infrastructure/Migrations/ApplicationDbContextModelSnapshot.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using FastArchitecture.Infrastructure.Persistence; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 7 | 8 | #nullable disable 9 | 10 | namespace FastArchitecture.Infrastructure.Migrations 11 | { 12 | [DbContext(typeof(ApplicationDbContext))] 13 | partial class ApplicationDbContextModelSnapshot : ModelSnapshot 14 | { 15 | protected override void BuildModel(ModelBuilder modelBuilder) 16 | { 17 | #pragma warning disable 612, 618 18 | modelBuilder.HasAnnotation("ProductVersion", "7.0.9"); 19 | 20 | modelBuilder.Entity("FastArchitecture.Domain.Order", b => 21 | { 22 | b.Property("Id") 23 | .ValueGeneratedOnAdd() 24 | .HasColumnType("TEXT"); 25 | 26 | b.Property("Name") 27 | .IsRequired() 28 | .HasColumnType("TEXT"); 29 | 30 | b.Property("Status") 31 | .IsRequired() 32 | .HasColumnType("TEXT"); 33 | 34 | b.Property("UserId") 35 | .IsRequired() 36 | .HasColumnType("TEXT"); 37 | 38 | b.HasKey("Id"); 39 | 40 | b.ToTable("Orders"); 41 | }); 42 | #pragma warning restore 612, 618 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/FastArchitecture.Infrastructure/Migrations/20230714170507_InitialCreate.Designer.cs: -------------------------------------------------------------------------------- 1 | // 2 | using System; 3 | using FastArchitecture.Infrastructure.Persistence; 4 | using Microsoft.EntityFrameworkCore; 5 | using Microsoft.EntityFrameworkCore.Infrastructure; 6 | using Microsoft.EntityFrameworkCore.Migrations; 7 | using Microsoft.EntityFrameworkCore.Storage.ValueConversion; 8 | 9 | #nullable disable 10 | 11 | namespace FastArchitecture.Infrastructure.Migrations 12 | { 13 | [DbContext(typeof(ApplicationDbContext))] 14 | [Migration("20230714170507_InitialCreate")] 15 | partial class InitialCreate 16 | { 17 | /// 18 | protected override void BuildTargetModel(ModelBuilder modelBuilder) 19 | { 20 | #pragma warning disable 612, 618 21 | modelBuilder.HasAnnotation("ProductVersion", "7.0.9"); 22 | 23 | modelBuilder.Entity("FastArchitecture.Domain.Order", b => 24 | { 25 | b.Property("Id") 26 | .ValueGeneratedOnAdd() 27 | .HasColumnType("TEXT"); 28 | 29 | b.Property("Name") 30 | .IsRequired() 31 | .HasColumnType("TEXT"); 32 | 33 | b.Property("Status") 34 | .IsRequired() 35 | .HasColumnType("TEXT"); 36 | 37 | b.Property("UserId") 38 | .IsRequired() 39 | .HasColumnType("TEXT"); 40 | 41 | b.HasKey("Id"); 42 | 43 | b.ToTable("Orders"); 44 | }); 45 | #pragma warning restore 612, 618 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Queries/GetOrderByName.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | using Microsoft.EntityFrameworkCore; 3 | 4 | namespace FastArchitecture.Handlers.Orders.Queries; 5 | 6 | public static class GetOrderByName 7 | { 8 | public sealed class Query : IQuery> 9 | { 10 | public string Name { get; set; } = ""; 11 | } 12 | 13 | public sealed class Response 14 | { 15 | public Guid Id { get; private set; } 16 | public string Name { get; private set; } 17 | public string CustomerName { get; private set; } 18 | 19 | public Response(Domain.Order order) 20 | { 21 | Id = order.Id; 22 | Name = order.Name; 23 | CustomerName = order.Name; 24 | } 25 | 26 | public static Response Create(Domain.Order order) 27 | { 28 | return new Response(order); 29 | } 30 | } 31 | 32 | public sealed class Handler : QueryHandler 33 | { 34 | public Handler(IHandlerContext context) : base(context) 35 | { 36 | } 37 | 38 | public override async Task> ExecuteAsync(Query query, CancellationToken ct) 39 | { 40 | var order = await DbContext 41 | .Orders 42 | .Where(x => x.Name == query.Name) 43 | // .Where(x => x.UserId == RequestContext.UserId) 44 | .SingleOrDefaultAsync(ct); 45 | 46 | if (order is null) 47 | { 48 | return Error("Order with name {0} not found.", query.Name); 49 | } 50 | 51 | return Success(new Response(order)); 52 | } 53 | } 54 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/FastArchitecture.Functions.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | net7.0 4 | v4 5 | Exe 6 | enable 7 | enable 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | PreserveNewest 28 | 29 | 30 | PreserveNewest 31 | Never 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Program.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Registration; 2 | using FastArchitecture.Infrastructure.Persistence; 3 | using FastEndpoints; 4 | using FastEndpoints.Swagger; 5 | using Microsoft.EntityFrameworkCore; 6 | using Serilog; 7 | 8 | /* 9 | * TODO: exmaple of Authorization 10 | * TODO: example of IActionFilter 11 | */ 12 | 13 | var builder = WebApplication.CreateBuilder(args); 14 | 15 | builder.Host.UseSerilog((hostContext, services, configuration) => 16 | { 17 | configuration 18 | .WriteTo.Console(); 19 | }); 20 | 21 | builder.Services.AddResponseCaching(); 22 | 23 | builder.Services.SwaggerDocument(o => 24 | { 25 | o.DocumentSettings = s => 26 | { 27 | s.DocumentName = "Initial Release"; 28 | s.Title = "FastArchitecture.Api"; 29 | s.Version = "v1.0"; 30 | }; 31 | }) 32 | .SwaggerDocument(o => 33 | { 34 | o.MaxEndpointVersion = 1; 35 | o.DocumentSettings = s => 36 | { 37 | s.DocumentName = "Release 1.0"; 38 | s.Title = "FastArchitecture.Api"; 39 | s.Version = "v1.0"; 40 | }; 41 | }); 42 | 43 | builder.Services.AddApiDependencies(); 44 | 45 | var app = builder.Build(); 46 | 47 | app.UseHttpsRedirection(); 48 | app.UseAuthorization(); 49 | app.UseResponseCaching(); 50 | app.UseFastEndpoints(c => 51 | { 52 | c.Versioning.Prefix = "v"; 53 | c.Versioning.PrependToRoute = true; 54 | }); 55 | 56 | app.UseSwaggerGen(); 57 | 58 | if (app.Environment.IsDevelopment()) 59 | { 60 | /* 61 | * Do not run this in production, not reall recommended 62 | * https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying?tabs=dotnet-core-cli#apply-migrations-at-runtime 63 | */ 64 | 65 | using (var scope = app.Services.CreateScope()) 66 | { 67 | var dbContext = scope.ServiceProvider.GetRequiredService(); 68 | dbContext.Database.Migrate(); 69 | } 70 | } 71 | 72 | app.Run(); -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Abstractions/IHandlerResponse.cs: -------------------------------------------------------------------------------- 1 | namespace FastArchitecture.Handlers.Abstractions; 2 | 3 | public interface IHandlerResponse 4 | { 5 | } 6 | 7 | public interface IHandlerResponse : IHandlerResponse 8 | { 9 | TResponse Payload { get; } 10 | bool IsSuccess { get; } 11 | bool IsFailure { get; } 12 | string Message { get; } 13 | } 14 | 15 | internal class HandlerResponse : IHandlerResponse 16 | { 17 | public bool IsSuccess { get; protected set; } 18 | public bool IsFailure => !IsSuccess; 19 | public string Message { get; protected set; } = string.Empty; 20 | 21 | internal HandlerResponse() 22 | { 23 | IsSuccess = true; 24 | } 25 | 26 | internal HandlerResponse(string message, params object[] parameters) 27 | { 28 | IsSuccess = false; 29 | Message = message; 30 | } 31 | 32 | internal static IHandlerResponse CreateEmpty() 33 | { 34 | return new HandlerResponse(); 35 | } 36 | 37 | internal static IHandlerResponse CreateError(string message, params object[] parameters) 38 | { 39 | return new HandlerResponse(message, parameters); 40 | } 41 | } 42 | 43 | internal sealed class HandlerResponse : HandlerResponse, IHandlerResponse 44 | { 45 | internal HandlerResponse(TResponse payload) 46 | { 47 | Payload = payload; 48 | IsSuccess = true; 49 | } 50 | 51 | internal HandlerResponse(string message, params object[] parameters) 52 | { 53 | IsSuccess = false; 54 | Message = string.Format(message, parameters); 55 | } 56 | 57 | public TResponse Payload { get; private set; } 58 | 59 | internal static IHandlerResponse Create(TResponse payload) 60 | { 61 | return new HandlerResponse(payload); 62 | } 63 | 64 | internal new static IHandlerResponse CreateError(string message, params object[] parameters) 65 | { 66 | return new HandlerResponse(message, parameters); 67 | } 68 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Api/Abstractions/ApiEndpoints.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | using FastEndpoints; 3 | 4 | namespace FastArchitecture.Api; 5 | public class ApiEndpoint : Endpoint where TRequest : ICommand 6 | { 7 | protected async Task SendAsync(ICommand command, CancellationToken cancellationToken) 8 | { 9 | await command.ExecuteAsync(cancellationToken); 10 | await SendNoContentAsync(cancellationToken); 11 | } 12 | } 13 | 14 | public class ApiEndpointWithoutRequest : EndpointWithoutRequest where TRequest: ICommand, new() 15 | { 16 | protected async Task SendAsync(CancellationToken cancellationToken) 17 | { 18 | var command = new TRequest(); 19 | await command.ExecuteAsync(cancellationToken); 20 | await SendNoContentAsync(cancellationToken); 21 | } 22 | } 23 | 24 | 25 | public class ApiEndpoint : Endpoint where TRequest : notnull 26 | { 27 | protected async Task SendAsync(ICommand> command, CancellationToken cancellationToken) 28 | { 29 | var handlerResponse = await command.ExecuteAsync(cancellationToken); 30 | 31 | if (handlerResponse.IsSuccess) 32 | { 33 | await SendAsync(handlerResponse.Payload, cancellation: cancellationToken); 34 | return; 35 | } 36 | 37 | AddError(handlerResponse.Message); 38 | 39 | await SendErrorsAsync(cancellation: cancellationToken); 40 | } 41 | 42 | protected async Task SendAsync(IQuery> command, CancellationToken cancellationToken) 43 | { 44 | var handlerResponse = await command.ExecuteAsync(cancellationToken); 45 | 46 | if (handlerResponse.IsSuccess) 47 | { 48 | await SendAsync(handlerResponse.Payload, cancellation: cancellationToken); 49 | return; 50 | } 51 | 52 | AddError(handlerResponse.Message); 53 | 54 | await SendErrorsAsync(cancellation: cancellationToken); 55 | } 56 | } -------------------------------------------------------------------------------- /tests/FastArchitecture.UnitTests/Handlers/Orders/CreateOrderTests.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Domain; 2 | using FastArchitecture.Handlers.Commands; 3 | 4 | namespace FastArchitecture.Handlers.Orders; 5 | 6 | public class CreateOrderTests 7 | { 8 | private static readonly string NewOrderName = "#0003"; 9 | private static readonly string NewOrderStatus = "created"; 10 | 11 | private static CreateOrder.Handler GetHandler(ApplicationDbContext dbContext) 12 | { 13 | return new CreateOrder.Handler(HandlerContextFactory.GetHandlerContext(dbContext)); 14 | } 15 | 16 | private static void SetTestData(ApplicationDbContext dc) 17 | { 18 | var orders = new List { 19 | Order.Create("#0001"), 20 | Order.Create("#0002"), 21 | }; 22 | 23 | dc.Orders.AddRange(orders); 24 | dc.SaveChanges(); 25 | } 26 | 27 | [Fact] 28 | public async Task Create_Order_ReturnEmpty() 29 | { 30 | var dc = InMemoryDbContextFactory.Create(); 31 | SetTestData(dc); 32 | 33 | var command = new CreateOrder.Command() 34 | { 35 | Name = NewOrderName 36 | }; 37 | 38 | var expectedName = NewOrderName; 39 | var expectedStatus = NewOrderStatus; 40 | var expectedCount = 3; 41 | 42 | await GetHandler(dc).ExecuteAsync(command, default); 43 | 44 | var result = dc.Orders.SingleOrDefault(o => o.Name == NewOrderName); 45 | var actualCount = dc.Orders.Count(); 46 | 47 | Assert.NotNull(result); 48 | Assert.Equal(expectedName, result.Name); 49 | Assert.Equal(expectedStatus, result.Status); 50 | Assert.Equal(expectedCount, expectedCount); 51 | } 52 | 53 | [Fact] 54 | public void Create_Order_ReturnNameTooShort() 55 | { 56 | var dc = InMemoryDbContextFactory.Create(); 57 | SetTestData(dc); 58 | 59 | var command = new CreateOrder.Command() 60 | { 61 | Name = "" 62 | }; 63 | 64 | Assert.ThrowsAsync(async () => await GetHandler(dc).ExecuteAsync(command, default)); 65 | } 66 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Handlers/Orders/Commands/CreateDraftOrder.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Handlers.Abstractions; 2 | using FastEndpoints; 3 | using FluentValidation; 4 | using Serilog; 5 | 6 | namespace FastArchitecture.Handlers.Orders.Commands; 7 | 8 | public static class CreateDraftOrder 9 | { 10 | public sealed class Command : ICommand> 11 | { 12 | public string Name { get; set; } = ""; 13 | } 14 | 15 | // Handler response can sit within handler (here) or in "Models" and be shared, that's up to you! 16 | public sealed class Response 17 | { 18 | public Guid Id { get; private set; } 19 | public string Name { get; private set; } 20 | public string CustomerName { get; private set; } 21 | 22 | public Response(Domain.Order order) 23 | { 24 | Id = order.Id; 25 | Name = order.Name; 26 | CustomerName = order.Name; 27 | } 28 | 29 | public static Response Create(Domain.Order order) 30 | { 31 | return new Response(order); 32 | } 33 | } 34 | 35 | public sealed class MyValidator : Validator 36 | { 37 | public MyValidator() 38 | { 39 | RuleFor(x => x.Name) 40 | .MinimumLength(5) 41 | .WithMessage("Order name is too short!"); 42 | } 43 | } 44 | 45 | public sealed class Handler : Abstractions.CommandHandler 46 | { 47 | private readonly ILogger _logger; 48 | 49 | public Handler(IHandlerContext context) : base(context) 50 | { 51 | _logger = context.Logger; 52 | } 53 | 54 | public override async Task> ExecuteAsync(Command command, CancellationToken ct) 55 | { 56 | var order = Domain.Order.CreateDraft(command.Name); 57 | 58 | await DbContext.Orders.AddAsync(order, ct); 59 | await DbContext.SaveChangesAsync(ct); 60 | 61 | _logger.Information("In need to log something here: {@order}", order); 62 | 63 | return Success(new Response(order)); 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/Logging/FunctionLog.cs: -------------------------------------------------------------------------------- 1 | using Serilog; 2 | 3 | namespace FastArchitecture.Functions.Logging; 4 | 5 | /// 6 | /// An ILogger wrapper with a function-specific enriched context and log message templating. 7 | /// 8 | public class FunctionLog 9 | { 10 | private ILogger _logger; 11 | private readonly string _functionName; 12 | 13 | public FunctionLog(ILogger logger, string functionName) 14 | { 15 | _logger = logger; 16 | _functionName = functionName; 17 | } 18 | 19 | public ILogger SetInvocationId(string id) 20 | { 21 | _logger = _logger.ForContext("InvocationId", id); 22 | return _logger; 23 | } 24 | 25 | public void Information(string messageTemplate, params object[] propertyValues) 26 | { 27 | messageTemplate = string.Concat("<{FunctionName:l}> ", messageTemplate); 28 | 29 | switch (propertyValues.Length) 30 | { 31 | case 1: 32 | _logger.Information(messageTemplate, _functionName, propertyValues[0]); 33 | break; 34 | 35 | case 2: 36 | _logger.Information(messageTemplate, _functionName, propertyValues[0], propertyValues[1]); 37 | break; 38 | 39 | case 3: 40 | _logger.Information(messageTemplate, _functionName, propertyValues[0], propertyValues[1], propertyValues[2]); 41 | break; 42 | 43 | default: 44 | _logger.Information(messageTemplate, _functionName, propertyValues); 45 | break; 46 | } 47 | } 48 | 49 | public void Warning(string messageTemplate, params object[] propertyValues) 50 | { 51 | messageTemplate = string.Concat("<{FunctionName:l}> ", messageTemplate); 52 | 53 | switch (propertyValues.Length) 54 | { 55 | case 1: 56 | _logger.Warning(messageTemplate, _functionName, propertyValues[0]); 57 | break; 58 | 59 | case 2: 60 | _logger.Warning(messageTemplate, _functionName, propertyValues[0], propertyValues[1]); 61 | break; 62 | 63 | case 3: 64 | _logger.Warning(messageTemplate, _functionName, propertyValues[0], propertyValues[1], propertyValues[2]); 65 | break; 66 | 67 | default: 68 | _logger.Warning(messageTemplate, _functionName, propertyValues); 69 | break; 70 | } 71 | } 72 | 73 | public void Error(string messageTemplate, params object[] propertyValues) 74 | { 75 | _logger.Error(string.Concat("<{FunctionName:l}> ", messageTemplate), _functionName, propertyValues); 76 | } 77 | 78 | public void Error(Exception exception) 79 | { 80 | _logger.Error(exception, string.Concat("<{FunctionName:l}> ", exception.Message), _functionName); 81 | } 82 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | build/ 14 | bld/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | .vs/ 18 | 19 | # MSTest test Results 20 | [Tt]est[Rr]esult*/ 21 | [Bb]uild[Ll]og.* 22 | 23 | #NUNIT 24 | *.VisualState.xml 25 | TestResult.xml 26 | 27 | # Build Results of an ATL Project 28 | [Dd]ebugPS/ 29 | [Rr]eleasePS/ 30 | dlldata.c 31 | 32 | *_i.c 33 | *_p.c 34 | *_i.h 35 | *.ilk 36 | *.meta 37 | *.obj 38 | *.pch 39 | *.pdb 40 | *.pgc 41 | *.pgd 42 | *.rsp 43 | *.sbr 44 | *.tlb 45 | *.tli 46 | *.tlh 47 | *.tmp 48 | *.tmp_proj 49 | *.log 50 | *.vspscc 51 | *.vssscc 52 | .builds 53 | *.pidb 54 | *.svclog 55 | *.scc 56 | 57 | # Chutzpah Test files 58 | _Chutzpah* 59 | 60 | # Visual C++ cache files 61 | ipch/ 62 | *.aps 63 | *.ncb 64 | *.opensdf 65 | *.sdf 66 | *.cachefile 67 | 68 | # Visual Studio profiler 69 | *.psess 70 | *.vsp 71 | *.vspx 72 | 73 | # TFS 2012 Local Workspace 74 | $tf/ 75 | 76 | # Guidance Automation Toolkit 77 | *.gpState 78 | 79 | # ReSharper is a .NET coding add-in 80 | _ReSharper*/ 81 | *.[Rr]e[Ss]harper 82 | *.DotSettings.user 83 | 84 | # JustCode is a .NET coding addin-in 85 | .JustCode 86 | 87 | # TeamCity is a build add-in 88 | _TeamCity* 89 | 90 | # DotCover is a Code Coverage Tool 91 | *.dotCover 92 | 93 | # NCrunch 94 | *.ncrunch* 95 | _NCrunch_* 96 | .*crunch*.local.xml 97 | 98 | # MightyMoose 99 | *.mm.* 100 | AutoTest.Net/ 101 | 102 | # Web workbench (sass) 103 | .sass-cache/ 104 | 105 | # Installshield output folder 106 | [Ee]xpress/ 107 | 108 | # DocProject is a documentation generator add-in 109 | DocProject/buildhelp/ 110 | DocProject/Help/*.HxT 111 | DocProject/Help/*.HxC 112 | DocProject/Help/*.hhc 113 | DocProject/Help/*.hhk 114 | DocProject/Help/*.hhp 115 | DocProject/Help/Html2 116 | DocProject/Help/html 117 | 118 | # Click-Once directory 119 | publish/ 120 | 121 | # Publish Web Output 122 | *.[Pp]ublish.xml 123 | *.azurePubxml 124 | 125 | # NuGet Packages Directory 126 | packages/* 127 | 128 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 129 | # This line needs to be after the ignore of the build folder (and the packages folder if the line above has been uncommented) 130 | !packages/build/ 131 | 132 | # Windows Azure Build Output 133 | csx/ 134 | *.build.csdef 135 | 136 | # Windows Store app package directory 137 | AppPackages/ 138 | 139 | # Others 140 | *.Cache 141 | ClientBin/ 142 | [Ss]tyle[Cc]op.* 143 | ~$* 144 | *~ 145 | *.dbmdl 146 | *.dbproj.schemaview 147 | *.pfx 148 | *.publishsettings 149 | node_modules/ 150 | 151 | # RIA/Silverlight projects 152 | Generated_Code/ 153 | 154 | # Backup & report files from converting an old project file to a newer 155 | # Visual Studio version. Backup files are not needed, because we have git ;-) 156 | _UpgradeReport_Files/ 157 | Backup*/ 158 | UpgradeLog*.XML 159 | UpgradeLog*.htm 160 | 161 | # SQL Server files 162 | *.mdf 163 | *.ldf 164 | 165 | # Business Intelligence projects 166 | *.rdl.data 167 | *.bim.layout 168 | *.bim_*.settings 169 | 170 | # Microsoft Fakes 171 | FakesAssemblies/ 172 | 173 | # Windows image file caches 174 | Thumbs.db 175 | ehthumbs.db 176 | 177 | # Folder config file 178 | Desktop.ini 179 | 180 | # Recycle Bin used on file shares 181 | $RECYCLE.BIN/ 182 | 183 | # TabStudio 184 | *.tss 185 | 186 | # Compiled web assets 187 | dist/ 188 | 189 | # Generated tools 190 | tools/* 191 | 192 | .idea 193 | 194 | # Ignore Firebase Service Worker out files 195 | src/Bilbayt.Admin/wwwroot/firebase-messaging-sw.js 196 | src/Bilbayt.Admin/wwwroot/firebase-messaging-sw.js.map 197 | 198 | src/Fiz.Api/Endpoints/Test/ 199 | 200 | **/.DS_Store 201 | 202 | *.db 203 | -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/Abstractions/FunctionBase.cs: -------------------------------------------------------------------------------- 1 | using FastArchitecture.Functions.Configuration; 2 | using FastArchitecture.Functions.Logging; 3 | 4 | using FastEndpoints; 5 | using FluentValidation; 6 | using Microsoft.Azure.Functions.Worker; 7 | using Serilog; 8 | using SerilogTimings.Extensions; 9 | using System.Text.Json; 10 | 11 | namespace FastArchitecture.Functions.Abstractions; 12 | 13 | public abstract class FunctionBase where T : class 14 | { 15 | protected FunctionLog Log { get; } 16 | 17 | private ILogger _logger; 18 | public readonly IValidator? _validator; 19 | 20 | private readonly string _functionName; 21 | 22 | private CancellationToken? _cancellationToken; 23 | 24 | public CancellationToken CancellationToken 25 | { 26 | get 27 | { 28 | _cancellationToken ??= default; 29 | 30 | return _cancellationToken.Value; 31 | } 32 | } 33 | 34 | protected FunctionBase(ILogger logger) 35 | { 36 | _logger = logger; 37 | _functionName = typeof(T).Name; 38 | Log = new FunctionLog(logger, _functionName); 39 | } 40 | 41 | protected FunctionBase(ILogger logger, IValidator validator) 42 | { 43 | _logger = logger; 44 | _functionName = typeof(T).Name; 45 | Log = new FunctionLog(logger, _functionName); 46 | _validator = validator; 47 | } 48 | 49 | protected async Task ExecuteAsync(string deserializedCommand, FunctionContext context) where TCommand : ICommand 50 | { 51 | try 52 | { 53 | using (Init(context, deserializedCommand, out TCommand command)) 54 | { 55 | await ThrowInvalid(command); 56 | 57 | await command.ExecuteAsync(CancellationToken); 58 | } 59 | } 60 | catch (Exception ex) 61 | { 62 | _logger.Error(ex, "<{functionName:l}> Execution failed for command {@deserializedCommand}", _functionName, deserializedCommand); 63 | throw; 64 | } 65 | } 66 | 67 | protected async Task ExecuteAsync(ICommand command, FunctionContext context) where TCommand : ICommand 68 | { 69 | try 70 | { 71 | using (Init(context)) 72 | { 73 | var commandInstance = (TCommand)command; 74 | 75 | await ThrowInvalid(command); 76 | 77 | await commandInstance.ExecuteAsync(CancellationToken); 78 | } 79 | } 80 | catch (Exception ex) 81 | { 82 | _logger.Error(ex, "<{functionName:l}> Execution failed for command {@command}", _functionName, command); 83 | throw; 84 | } 85 | } 86 | 87 | private async Task ThrowInvalid(TCommand command) where TCommand : ICommand 88 | { 89 | if (_validator is null) 90 | { 91 | return; 92 | } 93 | 94 | var validationContext = new FluentValidation.ValidationContext(command); 95 | var validationResult = await _validator.ValidateAsync(validationContext); 96 | 97 | if (!validationResult.IsValid) 98 | { 99 | throw new ValidationException($"<{_functionName}> Validation failed for command {@command}", validationResult.Errors); 100 | } 101 | } 102 | 103 | private IDisposable Init(FunctionContext context, string json, out TMessage message) 104 | { 105 | _logger = Log.SetInvocationId(context.InvocationId); 106 | message = JsonSerializer.Deserialize(json, JsonOptions.Defaults)!; 107 | return _logger.TimeOperation("<{FunctionName:l}> Executing function for {@Message}", _functionName, message); 108 | } 109 | 110 | private IDisposable Init(FunctionContext context) 111 | { 112 | _logger = Log.SetInvocationId(context.InvocationId); 113 | return _logger.TimeOperation("<{FunctionName:l}> Executing function", _functionName); 114 | } 115 | } -------------------------------------------------------------------------------- /FastArchitecture.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.4.33205.214 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastArchitecture.Api", "src\FastArchitecture.Api\FastArchitecture.Api.csproj", "{AF9F459C-E0AE-42BC-B310-57BF4EDB0EE0}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastArchitecture.Handlers", "src\FastArchitecture.Handlers\FastArchitecture.Handlers.csproj", "{DB00867F-28D1-403B-A60B-F91781CCFD0F}" 9 | EndProject 10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastArchitecture.Domain", "src\FastArchitecture.Domain\FastArchitecture.Domain.csproj", "{00464DA1-AF50-428D-BA8E-A395ADD1333A}" 11 | EndProject 12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastArchitecture.Infrastructure", "src\FastArchitecture.Infrastructure\FastArchitecture.Infrastructure.csproj", "{FF5AB4F1-E877-429F-8A5C-BDD81BE85736}" 13 | EndProject 14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastArchitecture.UnitTests", "tests\FastArchitecture.UnitTests\FastArchitecture.UnitTests.csproj", "{22B54492-1F2D-4CC1-BDD5-B8DF8AF89AF3}" 15 | EndProject 16 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FastArchitecture.Functions", "src\FastArchitecture.Functions\FastArchitecture.Functions.csproj", "{D1DFFF6F-3AF4-4FB5-960B-AA4BFDBFA447}" 17 | EndProject 18 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FastArchitecture.Core", "src\FastArchitecture.Core\FastArchitecture.Core.csproj", "{AE50B370-D992-459A-A296-1D69DE12CD22}" 19 | EndProject 20 | Global 21 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 22 | Debug|Any CPU = Debug|Any CPU 23 | Release|Any CPU = Release|Any CPU 24 | EndGlobalSection 25 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 26 | {AF9F459C-E0AE-42BC-B310-57BF4EDB0EE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {AF9F459C-E0AE-42BC-B310-57BF4EDB0EE0}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {AF9F459C-E0AE-42BC-B310-57BF4EDB0EE0}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {AF9F459C-E0AE-42BC-B310-57BF4EDB0EE0}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {DB00867F-28D1-403B-A60B-F91781CCFD0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {DB00867F-28D1-403B-A60B-F91781CCFD0F}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {DB00867F-28D1-403B-A60B-F91781CCFD0F}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {DB00867F-28D1-403B-A60B-F91781CCFD0F}.Release|Any CPU.Build.0 = Release|Any CPU 34 | {00464DA1-AF50-428D-BA8E-A395ADD1333A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 35 | {00464DA1-AF50-428D-BA8E-A395ADD1333A}.Debug|Any CPU.Build.0 = Debug|Any CPU 36 | {00464DA1-AF50-428D-BA8E-A395ADD1333A}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 | {00464DA1-AF50-428D-BA8E-A395ADD1333A}.Release|Any CPU.Build.0 = Release|Any CPU 38 | {FF5AB4F1-E877-429F-8A5C-BDD81BE85736}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 39 | {FF5AB4F1-E877-429F-8A5C-BDD81BE85736}.Debug|Any CPU.Build.0 = Debug|Any CPU 40 | {FF5AB4F1-E877-429F-8A5C-BDD81BE85736}.Release|Any CPU.ActiveCfg = Release|Any CPU 41 | {FF5AB4F1-E877-429F-8A5C-BDD81BE85736}.Release|Any CPU.Build.0 = Release|Any CPU 42 | {22B54492-1F2D-4CC1-BDD5-B8DF8AF89AF3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 43 | {22B54492-1F2D-4CC1-BDD5-B8DF8AF89AF3}.Debug|Any CPU.Build.0 = Debug|Any CPU 44 | {22B54492-1F2D-4CC1-BDD5-B8DF8AF89AF3}.Release|Any CPU.ActiveCfg = Release|Any CPU 45 | {22B54492-1F2D-4CC1-BDD5-B8DF8AF89AF3}.Release|Any CPU.Build.0 = Release|Any CPU 46 | {D1DFFF6F-3AF4-4FB5-960B-AA4BFDBFA447}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 47 | {D1DFFF6F-3AF4-4FB5-960B-AA4BFDBFA447}.Debug|Any CPU.Build.0 = Debug|Any CPU 48 | {D1DFFF6F-3AF4-4FB5-960B-AA4BFDBFA447}.Release|Any CPU.ActiveCfg = Release|Any CPU 49 | {D1DFFF6F-3AF4-4FB5-960B-AA4BFDBFA447}.Release|Any CPU.Build.0 = Release|Any CPU 50 | {AE50B370-D992-459A-A296-1D69DE12CD22}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 51 | {AE50B370-D992-459A-A296-1D69DE12CD22}.Debug|Any CPU.Build.0 = Debug|Any CPU 52 | {AE50B370-D992-459A-A296-1D69DE12CD22}.Release|Any CPU.ActiveCfg = Release|Any CPU 53 | {AE50B370-D992-459A-A296-1D69DE12CD22}.Release|Any CPU.Build.0 = Release|Any CPU 54 | EndGlobalSection 55 | GlobalSection(SolutionProperties) = preSolution 56 | HideSolutionNode = FALSE 57 | EndGlobalSection 58 | GlobalSection(ExtensibilityGlobals) = postSolution 59 | SolutionGuid = {CDA2EFD5-1D19-4F42-B2BF-6A4D00B5147E} 60 | EndGlobalSection 61 | EndGlobal 62 | -------------------------------------------------------------------------------- /src/FastArchitecture.Functions/.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # Azure Functions localsettings file 5 | local.settings.json 6 | 7 | # User-specific files 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Build results 17 | [Dd]ebug/ 18 | [Dd]ebugPublic/ 19 | [Rr]elease/ 20 | [Rr]eleases/ 21 | x64/ 22 | x86/ 23 | bld/ 24 | [Bb]in/ 25 | [Oo]bj/ 26 | [Ll]og/ 27 | 28 | # Visual Studio 2015 cache/options directory 29 | .vs/ 30 | # Uncomment if you have tasks that create the project's static files in wwwroot 31 | #wwwroot/ 32 | 33 | # MSTest test Results 34 | [Tt]est[Rr]esult*/ 35 | [Bb]uild[Ll]og.* 36 | 37 | # NUNIT 38 | *.VisualState.xml 39 | TestResult.xml 40 | 41 | # Build Results of an ATL Project 42 | [Dd]ebugPS/ 43 | [Rr]eleasePS/ 44 | dlldata.c 45 | 46 | # DNX 47 | project.lock.json 48 | project.fragment.lock.json 49 | artifacts/ 50 | 51 | *_i.c 52 | *_p.c 53 | *_i.h 54 | *.ilk 55 | *.meta 56 | *.obj 57 | *.pch 58 | *.pdb 59 | *.pgc 60 | *.pgd 61 | *.rsp 62 | *.sbr 63 | *.tlb 64 | *.tli 65 | *.tlh 66 | *.tmp 67 | *.tmp_proj 68 | *.log 69 | *.vspscc 70 | *.vssscc 71 | .builds 72 | *.pidb 73 | *.svclog 74 | *.scc 75 | 76 | # Chutzpah Test files 77 | _Chutzpah* 78 | 79 | # Visual C++ cache files 80 | ipch/ 81 | *.aps 82 | *.ncb 83 | *.opendb 84 | *.opensdf 85 | *.sdf 86 | *.cachefile 87 | *.VC.db 88 | *.VC.VC.opendb 89 | 90 | # Visual Studio profiler 91 | *.psess 92 | *.vsp 93 | *.vspx 94 | *.sap 95 | 96 | # TFS 2012 Local Workspace 97 | $tf/ 98 | 99 | # Guidance Automation Toolkit 100 | *.gpState 101 | 102 | # ReSharper is a .NET coding add-in 103 | _ReSharper*/ 104 | *.[Rr]e[Ss]harper 105 | *.DotSettings.user 106 | 107 | # JustCode is a .NET coding add-in 108 | .JustCode 109 | 110 | # TeamCity is a build add-in 111 | _TeamCity* 112 | 113 | # DotCover is a Code Coverage Tool 114 | *.dotCover 115 | 116 | # NCrunch 117 | _NCrunch_* 118 | .*crunch*.local.xml 119 | nCrunchTemp_* 120 | 121 | # MightyMoose 122 | *.mm.* 123 | AutoTest.Net/ 124 | 125 | # Web workbench (sass) 126 | .sass-cache/ 127 | 128 | # Installshield output folder 129 | [Ee]xpress/ 130 | 131 | # DocProject is a documentation generator add-in 132 | DocProject/buildhelp/ 133 | DocProject/Help/*.HxT 134 | DocProject/Help/*.HxC 135 | DocProject/Help/*.hhc 136 | DocProject/Help/*.hhk 137 | DocProject/Help/*.hhp 138 | DocProject/Help/Html2 139 | DocProject/Help/html 140 | 141 | # Click-Once directory 142 | publish/ 143 | 144 | # Publish Web Output 145 | *.[Pp]ublish.xml 146 | *.azurePubxml 147 | # TODO: Comment the next line if you want to checkin your web deploy settings 148 | # but database connection strings (with potential passwords) will be unencrypted 149 | #*.pubxml 150 | *.publishproj 151 | 152 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 153 | # checkin your Azure Web App publish settings, but sensitive information contained 154 | # in these scripts will be unencrypted 155 | PublishScripts/ 156 | 157 | # NuGet Packages 158 | *.nupkg 159 | # The packages folder can be ignored because of Package Restore 160 | **/packages/* 161 | # except build/, which is used as an MSBuild target. 162 | !**/packages/build/ 163 | # Uncomment if necessary however generally it will be regenerated when needed 164 | #!**/packages/repositories.config 165 | # NuGet v3's project.json files produces more ignoreable files 166 | *.nuget.props 167 | *.nuget.targets 168 | 169 | # Microsoft Azure Build Output 170 | csx/ 171 | *.build.csdef 172 | 173 | # Microsoft Azure Emulator 174 | ecf/ 175 | rcf/ 176 | 177 | # Windows Store app package directories and files 178 | AppPackages/ 179 | BundleArtifacts/ 180 | Package.StoreAssociation.xml 181 | _pkginfo.txt 182 | 183 | # Visual Studio cache files 184 | # files ending in .cache can be ignored 185 | *.[Cc]ache 186 | # but keep track of directories ending in .cache 187 | !*.[Cc]ache/ 188 | 189 | # Others 190 | ClientBin/ 191 | ~$* 192 | *~ 193 | *.dbmdl 194 | *.dbproj.schemaview 195 | *.jfm 196 | *.pfx 197 | *.publishsettings 198 | node_modules/ 199 | orleans.codegen.cs 200 | 201 | # Since there are multiple workflows, uncomment next line to ignore bower_components 202 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 203 | #bower_components/ 204 | 205 | # RIA/Silverlight projects 206 | Generated_Code/ 207 | 208 | # Backup & report files from converting an old project file 209 | # to a newer Visual Studio version. Backup files are not needed, 210 | # because we have git ;-) 211 | _UpgradeReport_Files/ 212 | Backup*/ 213 | UpgradeLog*.XML 214 | UpgradeLog*.htm 215 | 216 | # SQL Server files 217 | *.mdf 218 | *.ldf 219 | 220 | # Business Intelligence projects 221 | *.rdl.data 222 | *.bim.layout 223 | *.bim_*.settings 224 | 225 | # Microsoft Fakes 226 | FakesAssemblies/ 227 | 228 | # GhostDoc plugin setting file 229 | *.GhostDoc.xml 230 | 231 | # Node.js Tools for Visual Studio 232 | .ntvs_analysis.dat 233 | 234 | # Visual Studio 6 build log 235 | *.plg 236 | 237 | # Visual Studio 6 workspace options file 238 | *.opt 239 | 240 | # Visual Studio LightSwitch build output 241 | **/*.HTMLClient/GeneratedArtifacts 242 | **/*.DesktopClient/GeneratedArtifacts 243 | **/*.DesktopClient/ModelManifest.xml 244 | **/*.Server/GeneratedArtifacts 245 | **/*.Server/ModelManifest.xml 246 | _Pvt_Extensions 247 | 248 | # Paket dependency manager 249 | .paket/paket.exe 250 | paket-files/ 251 | 252 | # FAKE - F# Make 253 | .fake/ 254 | 255 | # JetBrains Rider 256 | .idea/ 257 | *.sln.iml 258 | 259 | # CodeRush 260 | .cr/ 261 | 262 | # Python Tools for Visual Studio (PTVS) 263 | __pycache__/ 264 | *.pyc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------