From eace5f633ef8bb3346390d5ed83587515c454dcd Mon Sep 17 00:00:00 2001 From: Shahanaz Sultana Date: Sat, 1 May 2021 18:26:49 +0600 Subject: [PATCH 1/7] Resulting API created with Domain and Infrastructure --- eSchool.sln | 58 +++++++++++++++-- .../Application/Behaviors/LoggingBehavior.cs | 48 ++++++++++++++ .../Commands/ResultingApplicationCommand.cs | 14 ++++ .../ResultingApplicationCommandHandler.cs | 43 +++++++++++++ .../Queries/FindAllResultHandler.cs | 30 +++++++++ .../Application/Queries/FindAllResultQuery.cs | 14 ++++ .../ResultingApplicationCommandValidator.cs | 20 ++++++ .../Controllers/ResultingController.cs | 40 ++++++++++++ .../Extensions/ServiceCollectionExtension.cs | 34 ++++++++++ .../Resulting/Resulting.API/Program.cs | 26 ++++++++ .../Resulting.API/Resulting.API.csproj | 21 ++++++ .../Resulting/Resulting.API/Startup.cs | 56 ++++++++++++++++ .../Resulting.API/WebHostExtensions.cs | 64 +++++++++++++++++++ .../appsettings.Development.json | 9 +++ .../Resulting/Resulting.API/appsettings.json | 10 +++ .../ResultingAggregate/IResultRepository.cs | 21 ++++++ .../ResultingAggregate/Results.cs | 33 ++++++++++ .../Resulting.Domain/Resulting.Domain.csproj | 7 ++ .../Resulting.Domain/SeedWork/Entity.cs | 13 ++++ .../SeedWork/IAggregateRoot.cs | 16 +++++ .../Resulting.Domain/SeedWork/IRepository.cs | 17 +++++ .../Repositories/ResultingRepository.cs | 45 +++++++++++++ .../Resulting.Infrastructure.csproj | 19 ++++++ .../ResultingContext.cs | 38 +++++++++++ 24 files changed, 691 insertions(+), 5 deletions(-) create mode 100644 src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs create mode 100644 src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs create mode 100644 src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs create mode 100644 src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs create mode 100644 src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs create mode 100644 src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs create mode 100644 src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs create mode 100644 src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs create mode 100644 src/Services/Resulting/Resulting.API/Program.cs create mode 100644 src/Services/Resulting/Resulting.API/Resulting.API.csproj create mode 100644 src/Services/Resulting/Resulting.API/Startup.cs create mode 100644 src/Services/Resulting/Resulting.API/WebHostExtensions.cs create mode 100644 src/Services/Resulting/Resulting.API/appsettings.Development.json create mode 100644 src/Services/Resulting/Resulting.API/appsettings.json create mode 100644 src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs create mode 100644 src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs create mode 100644 src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj create mode 100644 src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs create mode 100644 src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs create mode 100644 src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs create mode 100644 src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs create mode 100644 src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj create mode 100644 src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs diff --git a/eSchool.sln b/eSchool.sln index 02ebdc1a..22630d14 100644 --- a/eSchool.sln +++ b/eSchool.sln @@ -27,19 +27,27 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebStatus", "src\Web\WebSta EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{74511F4E-FF9D-42C4-9531-A75C61270B73}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGateways", "ApiGateways", "{256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frontend.Blazor", "Frontend.Blazor", "{0C00A596-0FE3-4FA6-B54B-FE2BE83371EF}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Client", "src\Web\Frontend.Blazor\Frontend.Blazor.Client\Frontend.Blazor.Client.csproj", "{53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Client", "src\Web\Frontend.Blazor\Frontend.Blazor.Client\Frontend.Blazor.Client.csproj", "{53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Server", "src\Web\Frontend.Blazor\Frontend.Blazor.Server\Frontend.Blazor.Server.csproj", "{3BABD4D9-56A1-4BA3-B30C-30E6765AB389}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Server", "src\Web\Frontend.Blazor\Frontend.Blazor.Server\Frontend.Blazor.Server.csproj", "{3BABD4D9-56A1-4BA3-B30C-30E6765AB389}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Resulting", "Resulting", "{F2EDA66F-2905-488E-88B2-0FCB0E9D8485}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resulting.Domain", "src\Services\Resulting\Resulting.Domain\Resulting.Domain.csproj", "{F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resulting.Infrastructure", "src\Services\Resulting\Resulting.Infrastructure\Resulting.Infrastructure.csproj", "{A354BD78-47E2-4175-92DA-00056F76517D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resulting.API", "src\Services\Resulting\Resulting.API\Resulting.API.csproj", "{EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -195,6 +203,42 @@ Global {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x64.Build.0 = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.ActiveCfg = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.Build.0 = Release|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x64.ActiveCfg = Debug|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x64.Build.0 = Debug|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x86.ActiveCfg = Debug|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x86.Build.0 = Debug|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|Any CPU.Build.0 = Release|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x64.ActiveCfg = Release|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x64.Build.0 = Release|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x86.ActiveCfg = Release|Any CPU + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x86.Build.0 = Release|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x64.ActiveCfg = Debug|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x64.Build.0 = Debug|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x86.ActiveCfg = Debug|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x86.Build.0 = Debug|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Release|Any CPU.Build.0 = Release|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x64.ActiveCfg = Release|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x64.Build.0 = Release|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x86.ActiveCfg = Release|Any CPU + {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x86.Build.0 = Release|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x64.ActiveCfg = Debug|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x64.Build.0 = Debug|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x86.ActiveCfg = Debug|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x86.Build.0 = Debug|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|Any CPU.ActiveCfg = Release|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|Any CPU.Build.0 = Release|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x64.ActiveCfg = Release|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x64.Build.0 = Release|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x86.ActiveCfg = Release|Any CPU + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -217,6 +261,10 @@ Global {53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {3BABD4D9-56A1-4BA3-B30C-30E6765AB389} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {4EB86635-CF79-4D15-909E-C41C98B0B586} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} + {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} = {1C120673-72F4-4679-AC4C-68286E9091A5} + {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B} = {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} + {A354BD78-47E2-4175-92DA-00056F76517D} = {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} + {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57} = {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E418719F-3193-403E-AF58-9BE9F94FD8BE} diff --git a/src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs b/src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs new file mode 100644 index 00000000..97c12669 --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.Extensions.Logging; + +namespace Resulting.API.Application.Behaviors +{ + public class LoggingBehavior + : IPipelineBehavior + where TRequest : notnull + { + private readonly ILogger> _logger; + + public LoggingBehavior( + ILogger> logger) + { + _logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); + } + + public async Task Handle( + TRequest request, + CancellationToken cancellationToken, + RequestHandlerDelegate next) + { + if (next is null) + { + throw new System.ArgumentNullException(nameof(next)); + } + + _logger.LogInformation( + "Handling request {RequestName} ({@Request})", + request.GetType().Name, + request); + + var response = await next().ConfigureAwait(false); + + _logger.LogInformation( + "Request {RequestName} handled. Response: {@Response}", + request.GetType().Name, + response); + + return response; + } + } +} diff --git a/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs b/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs new file mode 100644 index 00000000..e0ed8352 --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MediatR; + +namespace Resulting.API.Application.Commands +{ + public record ResultingApplicationCommand( + string Result, + string GradeScale, + string Grade) + : IRequest; +} diff --git a/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs b/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs new file mode 100644 index 00000000..25a103d5 --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.Extensions.Logging; +using Resulting.Infrastructure; +using Resulting.Domain.AggregateModel.ResultingAggregate; + +namespace Resulting.API.Application.Commands +{ + public class ResultingApplicationCommandHandler : IRequestHandler + { + private readonly ILogger _logger; + private readonly ResultingContext _context; + + public ResultingApplicationCommandHandler( + ResultingContext context, + ILogger logger) + { + _context = context ?? throw new ArgumentNullException(nameof(context)); + _logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + + public async Task Handle( + ResultingApplicationCommand command, + CancellationToken cancellationToken) + { + if (command == null) + { + throw new ArgumentNullException(nameof(command)); + } + + var resulting = new Results(command.Result, command.GradeScale, command.Grade); + await _context.Resulting.AddAsync(resulting, cancellationToken) + .ConfigureAwait(false); + await _context.SaveChangesAsync(cancellationToken) + .ConfigureAwait(false); + return true; + } + } +} diff --git a/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs b/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs new file mode 100644 index 00000000..740b671c --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.EntityFrameworkCore; +using Resulting.Domain.AggregateModel.ResultingAggregate; +using Resulting.Infrastructure; + +namespace Resulting.API.Application.Queries +{ + public class FindAllResultHandler : IRequestHandler> + { + private readonly ResultingContext _context; + + public FindAllResultHandler(ResultingContext context) + { + _context = context ?? throw new System.ArgumentNullException(nameof(context)); + } + + public async Task> Handle( + FindAllResultQuery request, + CancellationToken cancellationToken) + { + return await _context.Resulting.ToListAsync(cancellationToken) + .ConfigureAwait(false); + } + } +} diff --git a/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs b/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs new file mode 100644 index 00000000..069e6bde --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using MediatR; +using Resulting.Domain.AggregateModel.ResultingAggregate; + +namespace Resulting.API.Application.Queries +{ + public class FindAllResultQuery + : IRequest> + { + } +} diff --git a/src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs b/src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs new file mode 100644 index 00000000..25bebd08 --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using FluentValidation; +using Resulting.API.Application.Commands; + +namespace Resulting.API.Application.Validations +{ + public class ResultingApplicationCommandValidator + : AbstractValidator + { + public ResultingApplicationCommandValidator() + { + RuleFor(application => application.Result).NotEmpty(); + RuleFor(application => application.GradeScale).NotEmpty().EmailAddress(); + RuleFor(application => application.Grade).NotEmpty(); + } + } +} diff --git a/src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs b/src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs new file mode 100644 index 00000000..4ac0a47a --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using System.Threading.Tasks; +using MediatR; +using Microsoft.AspNetCore.Mvc; +using Resulting.API.Application.Commands; +using Resulting.API.Application.Queries; +using Resulting.Domain.AggregateModel.ResultingAggregate; + +namespace Resulting.API.Controllers +{ + [ApiController] + [Route("[controller]")] + public class ResultingController : ControllerBase + { + private readonly IMediator _mediator; + + public ResultingController(IMediator mediator) + { + _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); + } + + [HttpGet] + public async Task> Get(CancellationToken cancellationToken) + => await _mediator.Send(new FindAllResultQuery(), cancellationToken) + .ConfigureAwait(false); + + [HttpPost] + public async Task Post( + [FromBody] ResultingApplicationCommand command, + CancellationToken cancellationToken) + { + await _mediator.Send(command, cancellationToken) + .ConfigureAwait(false); + return Ok(); + } + } +} diff --git a/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs b/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs new file mode 100644 index 00000000..948f0a43 --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs @@ -0,0 +1,34 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Diagnostics.HealthChecks; + +namespace Resulting.API.Extensions +{ + public static class ServiceCollectionExtension + { + public static IServiceCollection AddCustomHealthChecks( + this IServiceCollection services, + IConfiguration configuration) + { + if (configuration == null) + { + throw new ArgumentNullException(nameof(configuration)); + } + + var hcBuilder = services.AddHealthChecks(); + + hcBuilder + .AddCheck("self", () => HealthCheckResult.Healthy()) + .AddSqlServer( + configuration["ConnectionStrings"], + name: "ResultingDB-check", + tags: new string[] { "resultingdb" }); + + return services; + } + } +} diff --git a/src/Services/Resulting/Resulting.API/Program.cs b/src/Services/Resulting/Resulting.API/Program.cs new file mode 100644 index 00000000..c15e1137 --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Resulting.API +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/src/Services/Resulting/Resulting.API/Resulting.API.csproj b/src/Services/Resulting/Resulting.API/Resulting.API.csproj new file mode 100644 index 00000000..097bc30b --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Resulting.API.csproj @@ -0,0 +1,21 @@ + + + + net5.0 + + + + + + + + + + + + + + + + + diff --git a/src/Services/Resulting/Resulting.API/Startup.cs b/src/Services/Resulting/Resulting.API/Startup.cs new file mode 100644 index 00000000..875e3eae --- /dev/null +++ b/src/Services/Resulting/Resulting.API/Startup.cs @@ -0,0 +1,56 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace Resulting.API +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "Resulting.API", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Resulting.API v1")); + } + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/src/Services/Resulting/Resulting.API/WebHostExtensions.cs b/src/Services/Resulting/Resulting.API/WebHostExtensions.cs new file mode 100644 index 00000000..ffd9721f --- /dev/null +++ b/src/Services/Resulting/Resulting.API/WebHostExtensions.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Data.SqlClient; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Polly; + +namespace Resulting.API +{ + public static class WebHostExtensions + { + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1031:Do not catch general exception types", + Justification = "Top level all exception catcher")] + public static IHost MigrateDbContext( + this IHost webHost, + Action seeder) + where TContext : DbContext + { + if (webHost == null) + { + throw new ArgumentNullException(nameof(webHost)); + } + + using var scope = webHost.Services.CreateScope(); + var services = scope.ServiceProvider; + var logger = services.GetRequiredService>(); + var context = services.GetRequiredService(); + + try + { + logger.LogInformation("Migrating database associated with context {ContextName}", typeof(TContext).Name); + + var retry = Policy.Handle() + .WaitAndRetry(new TimeSpan[] + { + TimeSpan.FromSeconds(5), + TimeSpan.FromSeconds(10), + TimeSpan.FromSeconds(15), + }); + + retry.Execute(() => + { + object p = context.Database.Migrate(); + seeder(context, services); + }); + + logger.LogInformation($"Migrated database associated with context {typeof(TContext).Name}"); + } + catch (Exception ex) + { + logger.LogError(ex, $"An error occurred while migrating the databases used on context {typeof(TContext).Name}"); + } + + return webHost; + + } + } +} diff --git a/src/Services/Resulting/Resulting.API/appsettings.Development.json b/src/Services/Resulting/Resulting.API/appsettings.Development.json new file mode 100644 index 00000000..8983e0fc --- /dev/null +++ b/src/Services/Resulting/Resulting.API/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/src/Services/Resulting/Resulting.API/appsettings.json b/src/Services/Resulting/Resulting.API/appsettings.json new file mode 100644 index 00000000..d9d9a9bf --- /dev/null +++ b/src/Services/Resulting/Resulting.API/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} diff --git a/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs b/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs new file mode 100644 index 00000000..2ba98aec --- /dev/null +++ b/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs @@ -0,0 +1,21 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Resulting.Domain.SeedWork; + +namespace Resulting.Domain.AggregateModel.ResultingAggregate +{ + public interface IResultRepository : IRepository + { + Results Add(Results enrollment); + + Results Update(Results enrollment); + + Task FindByIdAsync( + Guid id, + CancellationToken cancellationToken = default); + } +} diff --git a/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs b/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs new file mode 100644 index 00000000..164b6ee6 --- /dev/null +++ b/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Resulting.Domain.SeedWork; + +namespace Resulting.Domain.AggregateModel.ResultingAggregate +{ + public class Results : Entity, IAggregateRoot + { + public Results( + string Result, + string GradeScale, + string Grade) + { + Result = !string.IsNullOrWhiteSpace(Result) ? Result + : throw new ArgumentNullException(nameof(Result)); + GradeScale = !string.IsNullOrWhiteSpace(GradeScale) ? GradeScale + : throw new ArgumentNullException(nameof(GradeScale)); + Grade = !string.IsNullOrWhiteSpace(Grade) ? Grade + : throw new ArgumentNullException(nameof(Grade)); + } + + public string Result { get; private set; } + + public string GradeScale { get; private set; } + + public string Grade { get; private set; } + + public int Number { get; private set; } + } +} diff --git a/src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj b/src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj new file mode 100644 index 00000000..2f002aa3 --- /dev/null +++ b/src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj @@ -0,0 +1,7 @@ + + + + net5.0 + + + diff --git a/src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs b/src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs new file mode 100644 index 00000000..7648a3f4 --- /dev/null +++ b/src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Resulting.Domain.SeedWork +{ + public abstract class Entity + { + public Guid Id { get; protected set; } + } +} diff --git a/src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs b/src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs new file mode 100644 index 00000000..a14b651d --- /dev/null +++ b/src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Resulting.Domain.SeedWork +{ + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1040:Avoid empty interfaces", + Justification = "Marker interface")] + public interface IAggregateRoot + { + } +} diff --git a/src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs b/src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs new file mode 100644 index 00000000..c1b16d45 --- /dev/null +++ b/src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Resulting.Domain.SeedWork +{ + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1040:Avoid empty interfaces", + Justification = "Marker interface")] + public interface IRepository + where T : IAggregateRoot + { + } +} diff --git a/src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs b/src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs new file mode 100644 index 00000000..d44fb5c1 --- /dev/null +++ b/src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Resulting.Domain.AggregateModel.ResultingAggregate; + +namespace Resulting.Infrastructure.Repositories +{ + public class ResultingRepository : IResultRepository + { + private readonly ResultingContext _context; + + public ResultingRepository(ResultingContext context) + { + _context = context ?? throw new ArgumentNullException(nameof(context)); + } + + public Results Add(Results results) + { + return _context.Resulting + .Add(results) + .Entity; + } + + public async Task FindByIdAsync( + Guid id, + CancellationToken cancellationToken = default) + { + return await _context.Resulting + .Where(e => e.Id == id) + .SingleOrDefaultAsync(cancellationToken) + .ConfigureAwait(false); + } + + public Results Update(Results results) + { + return _context.Resulting + .Update(results) + .Entity; + } + } +} diff --git a/src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj b/src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj new file mode 100644 index 00000000..d2dd22fe --- /dev/null +++ b/src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj @@ -0,0 +1,19 @@ + + + + net5.0 + + + + + + + + + + + + + + + diff --git a/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs b/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs new file mode 100644 index 00000000..2c4e9416 --- /dev/null +++ b/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Design; +using Resulting.Domain.AggregateModel.ResultingAggregate; + +namespace Resulting.Infrastructure +{ + public class ResultingContext : DbContext + { + public ResultingContext(DbContextOptions options) + : base(options) + { + } + + public DbSet Resulting { get; set; } = default!; + } + + /// + /// Helper class for creating migration. To create new migration, run the + /// command from `Enrolling.Intrastructure` folder. + /// + /// $ dotnet ef migrations add name_of_migration --startup-project ../Enrolling.API. + /// + public class ResultingContextFactory : IDesignTimeDbContextFactory + { + public ResultingContext CreateDbContext(string[] args) + { + var optionsBuilder = new DbContextOptionsBuilder() + .UseSqlServer("Server=.;Initial Catalog=OpenCodeFoundation.ResultingDB;Integrated Security=true"); + + return new ResultingContext(optionsBuilder.Options); + } + } +} From 272189f973b03f89c45e78f0ca75b06baebb0da8 Mon Sep 17 00:00:00 2001 From: Shahanaz Sultana Date: Sat, 1 May 2021 19:48:33 +0600 Subject: [PATCH 2/7] Make build succeeded --- .../Extensions/ServiceCollectionExtension.cs | 12 ++++++------ .../Resulting.API/WebHostExtensions.cs | 10 +++++----- .../ResultingContext.cs | 18 +++++++++--------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs b/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs index 948f0a43..7cc4a48a 100644 --- a/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs +++ b/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs @@ -21,12 +21,12 @@ public static IServiceCollection AddCustomHealthChecks( var hcBuilder = services.AddHealthChecks(); - hcBuilder - .AddCheck("self", () => HealthCheckResult.Healthy()) - .AddSqlServer( - configuration["ConnectionStrings"], - name: "ResultingDB-check", - tags: new string[] { "resultingdb" }); + //hcBuilder + // .AddCheck("self", () => HealthCheckResult.Healthy()) + // .AddSqlServer( + // configuration["ConnectionStrings"], + // name: "ResultingDB-check", + // tags: new string[] { "resultingdb" }); return services; } diff --git a/src/Services/Resulting/Resulting.API/WebHostExtensions.cs b/src/Services/Resulting/Resulting.API/WebHostExtensions.cs index ffd9721f..85784678 100644 --- a/src/Services/Resulting/Resulting.API/WebHostExtensions.cs +++ b/src/Services/Resulting/Resulting.API/WebHostExtensions.cs @@ -44,11 +44,11 @@ public static IHost MigrateDbContext( TimeSpan.FromSeconds(15), }); - retry.Execute(() => - { - object p = context.Database.Migrate(); - seeder(context, services); - }); + //retry.Execute(() => + //{ + // object p = context.Database.Migrate(); + // seeder(context, services); + //}); logger.LogInformation($"Migrated database associated with context {typeof(TContext).Name}"); } diff --git a/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs b/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs index 2c4e9416..21b93fc4 100644 --- a/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs +++ b/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs @@ -25,14 +25,14 @@ public ResultingContext(DbContextOptions options) /// /// $ dotnet ef migrations add name_of_migration --startup-project ../Enrolling.API. /// - public class ResultingContextFactory : IDesignTimeDbContextFactory - { - public ResultingContext CreateDbContext(string[] args) - { - var optionsBuilder = new DbContextOptionsBuilder() - .UseSqlServer("Server=.;Initial Catalog=OpenCodeFoundation.ResultingDB;Integrated Security=true"); + //public class ResultingContextFactory : IDesignTimeDbContextFactory + //{ + // public ResultingContext CreateDbContext(string[] args) + // { + // var optionsBuilder = new DbContextOptionsBuilder() + // .UseSqlServer("Server=.;Initial Catalog=OpenCodeFoundation.ResultingDB;Integrated Security=true"); - return new ResultingContext(optionsBuilder.Options); - } - } + // return new ResultingContext(optionsBuilder.Options); + // } + //} } From 6cd68752b65cc37e5b48e278c0a5bc6efe786ff3 Mon Sep 17 00:00:00 2001 From: Shahanaz Sultana Date: Fri, 25 Jun 2021 16:21:45 +0600 Subject: [PATCH 3/7] Create basic new web API --- eSchool.sln | 62 +++++------------- .../Controllers/HelloWorldController.cs | 15 +++++ .../Controllers/WeatherForecastController.cs | 39 +++++++++++ .../ResultProcessing.API}/Program.cs | 10 +-- .../ResultProcessing.API.csproj | 11 ++++ .../ResultProcessing.API}/Startup.cs | 16 ++--- .../ResultProcessing.API/WeatherForecast.cs | 15 +++++ .../appsettings.Development.json | 0 .../ResultProcessing.API}/appsettings.json | 0 .../Application/Behaviors/LoggingBehavior.cs | 48 -------------- .../Commands/ResultingApplicationCommand.cs | 14 ---- .../ResultingApplicationCommandHandler.cs | 43 ------------- .../Queries/FindAllResultHandler.cs | 30 --------- .../Application/Queries/FindAllResultQuery.cs | 14 ---- .../ResultingApplicationCommandValidator.cs | 20 ------ .../Controllers/ResultingController.cs | 40 ------------ .../Extensions/ServiceCollectionExtension.cs | 34 ---------- .../Resulting.API/Resulting.API.csproj | 21 ------ .../Resulting.API/WebHostExtensions.cs | 64 ------------------- .../ResultingAggregate/IResultRepository.cs | 21 ------ .../ResultingAggregate/Results.cs | 33 ---------- .../Resulting.Domain/Resulting.Domain.csproj | 7 -- .../Resulting.Domain/SeedWork/Entity.cs | 13 ---- .../SeedWork/IAggregateRoot.cs | 16 ----- .../Resulting.Domain/SeedWork/IRepository.cs | 17 ----- .../Repositories/ResultingRepository.cs | 45 ------------- .../Resulting.Infrastructure.csproj | 19 ------ .../ResultingContext.cs | 38 ----------- 28 files changed, 107 insertions(+), 598 deletions(-) create mode 100644 src/Services/ResultProcessing/ResultProcessing.API/Controllers/HelloWorldController.cs create mode 100644 src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs rename src/Services/{Resulting/Resulting.API => ResultProcessing/ResultProcessing.API}/Program.cs (95%) create mode 100644 src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj rename src/Services/{Resulting/Resulting.API => ResultProcessing/ResultProcessing.API}/Startup.cs (78%) create mode 100644 src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs rename src/Services/{Resulting/Resulting.API => ResultProcessing/ResultProcessing.API}/appsettings.Development.json (100%) rename src/Services/{Resulting/Resulting.API => ResultProcessing/ResultProcessing.API}/appsettings.json (100%) delete mode 100644 src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs delete mode 100644 src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs delete mode 100644 src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs delete mode 100644 src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs delete mode 100644 src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs delete mode 100644 src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs delete mode 100644 src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs delete mode 100644 src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs delete mode 100644 src/Services/Resulting/Resulting.API/Resulting.API.csproj delete mode 100644 src/Services/Resulting/Resulting.API/WebHostExtensions.cs delete mode 100644 src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs delete mode 100644 src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs delete mode 100644 src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj delete mode 100644 src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs delete mode 100644 src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs delete mode 100644 src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs delete mode 100644 src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs delete mode 100644 src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj delete mode 100644 src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs diff --git a/eSchool.sln b/eSchool.sln index 22630d14..82203d75 100644 --- a/eSchool.sln +++ b/eSchool.sln @@ -41,13 +41,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Server", "s EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Resulting", "Resulting", "{F2EDA66F-2905-488E-88B2-0FCB0E9D8485}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ResultProcessing", "ResultProcessing", "{42B5BC23-92AF-4E3A-8C52-788355924951}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resulting.Domain", "src\Services\Resulting\Resulting.Domain\Resulting.Domain.csproj", "{F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resulting.Infrastructure", "src\Services\Resulting\Resulting.Infrastructure\Resulting.Infrastructure.csproj", "{A354BD78-47E2-4175-92DA-00056F76517D}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Resulting.API", "src\Services\Resulting\Resulting.API\Resulting.API.csproj", "{EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ResultProcessing.API", "src\Services\ResultProcessing\ResultProcessing.API\ResultProcessing.API.csproj", "{888AD861-8D13-497D-BCCE-E162A0DB4650}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -203,42 +199,18 @@ Global {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x64.Build.0 = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.ActiveCfg = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.Build.0 = Release|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x64.ActiveCfg = Debug|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x64.Build.0 = Debug|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x86.ActiveCfg = Debug|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Debug|x86.Build.0 = Debug|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|Any CPU.Build.0 = Release|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x64.ActiveCfg = Release|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x64.Build.0 = Release|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x86.ActiveCfg = Release|Any CPU - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B}.Release|x86.Build.0 = Release|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|Any CPU.Build.0 = Debug|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x64.ActiveCfg = Debug|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x64.Build.0 = Debug|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x86.ActiveCfg = Debug|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Debug|x86.Build.0 = Debug|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Release|Any CPU.ActiveCfg = Release|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Release|Any CPU.Build.0 = Release|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x64.ActiveCfg = Release|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x64.Build.0 = Release|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x86.ActiveCfg = Release|Any CPU - {A354BD78-47E2-4175-92DA-00056F76517D}.Release|x86.Build.0 = Release|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|Any CPU.Build.0 = Debug|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x64.ActiveCfg = Debug|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x64.Build.0 = Debug|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x86.ActiveCfg = Debug|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Debug|x86.Build.0 = Debug|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|Any CPU.ActiveCfg = Release|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|Any CPU.Build.0 = Release|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x64.ActiveCfg = Release|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x64.Build.0 = Release|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x86.ActiveCfg = Release|Any CPU - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57}.Release|x86.Build.0 = Release|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|Any CPU.Build.0 = Debug|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x64.ActiveCfg = Debug|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x64.Build.0 = Debug|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x86.ActiveCfg = Debug|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x86.Build.0 = Debug|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|Any CPU.ActiveCfg = Release|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|Any CPU.Build.0 = Release|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x64.ActiveCfg = Release|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x64.Build.0 = Release|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x86.ActiveCfg = Release|Any CPU + {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -261,10 +233,8 @@ Global {53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {3BABD4D9-56A1-4BA3-B30C-30E6765AB389} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {4EB86635-CF79-4D15-909E-C41C98B0B586} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} - {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} = {1C120673-72F4-4679-AC4C-68286E9091A5} - {F7D272AB-F77F-4B74-AC02-DA5FA8295B6B} = {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} - {A354BD78-47E2-4175-92DA-00056F76517D} = {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} - {EF46B70B-A8BB-4ED6-8C0A-B99CDF5E1A57} = {F2EDA66F-2905-488E-88B2-0FCB0E9D8485} + {42B5BC23-92AF-4E3A-8C52-788355924951} = {1C120673-72F4-4679-AC4C-68286E9091A5} + {888AD861-8D13-497D-BCCE-E162A0DB4650} = {42B5BC23-92AF-4E3A-8C52-788355924951} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E418719F-3193-403E-AF58-9BE9F94FD8BE} diff --git a/src/Services/ResultProcessing/ResultProcessing.API/Controllers/HelloWorldController.cs b/src/Services/ResultProcessing/ResultProcessing.API/Controllers/HelloWorldController.cs new file mode 100644 index 00000000..572d3a35 --- /dev/null +++ b/src/Services/ResultProcessing/ResultProcessing.API/Controllers/HelloWorldController.cs @@ -0,0 +1,15 @@ +using Microsoft.AspNetCore.Mvc; + +namespace ResultProcessing.API.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class HelloWorldController : ControllerBase + { + [HttpGet] + public ActionResult Ping() + { + return Ok("This is new Web API"); + } + } +} diff --git a/src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs b/src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs new file mode 100644 index 00000000..18635dbf --- /dev/null +++ b/src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace ResultProcessing.API.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/src/Services/Resulting/Resulting.API/Program.cs b/src/Services/ResultProcessing/ResultProcessing.API/Program.cs similarity index 95% rename from src/Services/Resulting/Resulting.API/Program.cs rename to src/Services/ResultProcessing/ResultProcessing.API/Program.cs index c15e1137..171e8e0e 100644 --- a/src/Services/Resulting/Resulting.API/Program.cs +++ b/src/Services/ResultProcessing/ResultProcessing.API/Program.cs @@ -1,13 +1,13 @@ -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; -namespace Resulting.API +namespace ResultProcessing.API { public class Program { diff --git a/src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj b/src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj new file mode 100644 index 00000000..28847161 --- /dev/null +++ b/src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/src/Services/Resulting/Resulting.API/Startup.cs b/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs similarity index 78% rename from src/Services/Resulting/Resulting.API/Startup.cs rename to src/Services/ResultProcessing/ResultProcessing.API/Startup.cs index 875e3eae..3eb7f1bd 100644 --- a/src/Services/Resulting/Resulting.API/Startup.cs +++ b/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs @@ -1,17 +1,11 @@ using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; using Microsoft.OpenApi.Models; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -namespace Resulting.API +namespace ResultProcessing.API { public class Startup { @@ -29,7 +23,7 @@ public void ConfigureServices(IServiceCollection services) services.AddControllers(); services.AddSwaggerGen(c => { - c.SwaggerDoc("v1", new OpenApiInfo { Title = "Resulting.API", Version = "v1" }); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "ResultProcessing.API", Version = "v1" }); }); } @@ -39,9 +33,11 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); - app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "Resulting.API v1")); } + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ResultProcessing.API v1")); + + app.UseHttpsRedirection(); app.UseRouting(); diff --git a/src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs b/src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs new file mode 100644 index 00000000..b8559deb --- /dev/null +++ b/src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace ResultProcessing.API +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/src/Services/Resulting/Resulting.API/appsettings.Development.json b/src/Services/ResultProcessing/ResultProcessing.API/appsettings.Development.json similarity index 100% rename from src/Services/Resulting/Resulting.API/appsettings.Development.json rename to src/Services/ResultProcessing/ResultProcessing.API/appsettings.Development.json diff --git a/src/Services/Resulting/Resulting.API/appsettings.json b/src/Services/ResultProcessing/ResultProcessing.API/appsettings.json similarity index 100% rename from src/Services/Resulting/Resulting.API/appsettings.json rename to src/Services/ResultProcessing/ResultProcessing.API/appsettings.json diff --git a/src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs b/src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs deleted file mode 100644 index 97c12669..00000000 --- a/src/Services/Resulting/Resulting.API/Application/Behaviors/LoggingBehavior.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediatR; -using Microsoft.Extensions.Logging; - -namespace Resulting.API.Application.Behaviors -{ - public class LoggingBehavior - : IPipelineBehavior - where TRequest : notnull - { - private readonly ILogger> _logger; - - public LoggingBehavior( - ILogger> logger) - { - _logger = logger ?? throw new System.ArgumentNullException(nameof(logger)); - } - - public async Task Handle( - TRequest request, - CancellationToken cancellationToken, - RequestHandlerDelegate next) - { - if (next is null) - { - throw new System.ArgumentNullException(nameof(next)); - } - - _logger.LogInformation( - "Handling request {RequestName} ({@Request})", - request.GetType().Name, - request); - - var response = await next().ConfigureAwait(false); - - _logger.LogInformation( - "Request {RequestName} handled. Response: {@Response}", - request.GetType().Name, - response); - - return response; - } - } -} diff --git a/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs b/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs deleted file mode 100644 index e0ed8352..00000000 --- a/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommand.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using MediatR; - -namespace Resulting.API.Application.Commands -{ - public record ResultingApplicationCommand( - string Result, - string GradeScale, - string Grade) - : IRequest; -} diff --git a/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs b/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs deleted file mode 100644 index 25a103d5..00000000 --- a/src/Services/Resulting/Resulting.API/Application/Commands/ResultingApplicationCommandHandler.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediatR; -using Microsoft.Extensions.Logging; -using Resulting.Infrastructure; -using Resulting.Domain.AggregateModel.ResultingAggregate; - -namespace Resulting.API.Application.Commands -{ - public class ResultingApplicationCommandHandler : IRequestHandler - { - private readonly ILogger _logger; - private readonly ResultingContext _context; - - public ResultingApplicationCommandHandler( - ResultingContext context, - ILogger logger) - { - _context = context ?? throw new ArgumentNullException(nameof(context)); - _logger = logger ?? throw new ArgumentNullException(nameof(logger)); - } - - public async Task Handle( - ResultingApplicationCommand command, - CancellationToken cancellationToken) - { - if (command == null) - { - throw new ArgumentNullException(nameof(command)); - } - - var resulting = new Results(command.Result, command.GradeScale, command.Grade); - await _context.Resulting.AddAsync(resulting, cancellationToken) - .ConfigureAwait(false); - await _context.SaveChangesAsync(cancellationToken) - .ConfigureAwait(false); - return true; - } - } -} diff --git a/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs b/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs deleted file mode 100644 index 740b671c..00000000 --- a/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultHandler.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediatR; -using Microsoft.EntityFrameworkCore; -using Resulting.Domain.AggregateModel.ResultingAggregate; -using Resulting.Infrastructure; - -namespace Resulting.API.Application.Queries -{ - public class FindAllResultHandler : IRequestHandler> - { - private readonly ResultingContext _context; - - public FindAllResultHandler(ResultingContext context) - { - _context = context ?? throw new System.ArgumentNullException(nameof(context)); - } - - public async Task> Handle( - FindAllResultQuery request, - CancellationToken cancellationToken) - { - return await _context.Resulting.ToListAsync(cancellationToken) - .ConfigureAwait(false); - } - } -} diff --git a/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs b/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs deleted file mode 100644 index 069e6bde..00000000 --- a/src/Services/Resulting/Resulting.API/Application/Queries/FindAllResultQuery.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using MediatR; -using Resulting.Domain.AggregateModel.ResultingAggregate; - -namespace Resulting.API.Application.Queries -{ - public class FindAllResultQuery - : IRequest> - { - } -} diff --git a/src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs b/src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs deleted file mode 100644 index 25bebd08..00000000 --- a/src/Services/Resulting/Resulting.API/Application/Validations/ResultingApplicationCommandValidator.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using FluentValidation; -using Resulting.API.Application.Commands; - -namespace Resulting.API.Application.Validations -{ - public class ResultingApplicationCommandValidator - : AbstractValidator - { - public ResultingApplicationCommandValidator() - { - RuleFor(application => application.Result).NotEmpty(); - RuleFor(application => application.GradeScale).NotEmpty().EmailAddress(); - RuleFor(application => application.Grade).NotEmpty(); - } - } -} diff --git a/src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs b/src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs deleted file mode 100644 index 4ac0a47a..00000000 --- a/src/Services/Resulting/Resulting.API/Controllers/ResultingController.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading; -using System.Threading.Tasks; -using MediatR; -using Microsoft.AspNetCore.Mvc; -using Resulting.API.Application.Commands; -using Resulting.API.Application.Queries; -using Resulting.Domain.AggregateModel.ResultingAggregate; - -namespace Resulting.API.Controllers -{ - [ApiController] - [Route("[controller]")] - public class ResultingController : ControllerBase - { - private readonly IMediator _mediator; - - public ResultingController(IMediator mediator) - { - _mediator = mediator ?? throw new ArgumentNullException(nameof(mediator)); - } - - [HttpGet] - public async Task> Get(CancellationToken cancellationToken) - => await _mediator.Send(new FindAllResultQuery(), cancellationToken) - .ConfigureAwait(false); - - [HttpPost] - public async Task Post( - [FromBody] ResultingApplicationCommand command, - CancellationToken cancellationToken) - { - await _mediator.Send(command, cancellationToken) - .ConfigureAwait(false); - return Ok(); - } - } -} diff --git a/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs b/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs deleted file mode 100644 index 7cc4a48a..00000000 --- a/src/Services/Resulting/Resulting.API/Extensions/ServiceCollectionExtension.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Diagnostics.HealthChecks; - -namespace Resulting.API.Extensions -{ - public static class ServiceCollectionExtension - { - public static IServiceCollection AddCustomHealthChecks( - this IServiceCollection services, - IConfiguration configuration) - { - if (configuration == null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - var hcBuilder = services.AddHealthChecks(); - - //hcBuilder - // .AddCheck("self", () => HealthCheckResult.Healthy()) - // .AddSqlServer( - // configuration["ConnectionStrings"], - // name: "ResultingDB-check", - // tags: new string[] { "resultingdb" }); - - return services; - } - } -} diff --git a/src/Services/Resulting/Resulting.API/Resulting.API.csproj b/src/Services/Resulting/Resulting.API/Resulting.API.csproj deleted file mode 100644 index 097bc30b..00000000 --- a/src/Services/Resulting/Resulting.API/Resulting.API.csproj +++ /dev/null @@ -1,21 +0,0 @@ - - - - net5.0 - - - - - - - - - - - - - - - - - diff --git a/src/Services/Resulting/Resulting.API/WebHostExtensions.cs b/src/Services/Resulting/Resulting.API/WebHostExtensions.cs deleted file mode 100644 index 85784678..00000000 --- a/src/Services/Resulting/Resulting.API/WebHostExtensions.cs +++ /dev/null @@ -1,64 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data.SqlClient; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; -using Microsoft.Extensions.Logging; -using Polly; - -namespace Resulting.API -{ - public static class WebHostExtensions - { - [System.Diagnostics.CodeAnalysis.SuppressMessage( - "Design", - "CA1031:Do not catch general exception types", - Justification = "Top level all exception catcher")] - public static IHost MigrateDbContext( - this IHost webHost, - Action seeder) - where TContext : DbContext - { - if (webHost == null) - { - throw new ArgumentNullException(nameof(webHost)); - } - - using var scope = webHost.Services.CreateScope(); - var services = scope.ServiceProvider; - var logger = services.GetRequiredService>(); - var context = services.GetRequiredService(); - - try - { - logger.LogInformation("Migrating database associated with context {ContextName}", typeof(TContext).Name); - - var retry = Policy.Handle() - .WaitAndRetry(new TimeSpan[] - { - TimeSpan.FromSeconds(5), - TimeSpan.FromSeconds(10), - TimeSpan.FromSeconds(15), - }); - - //retry.Execute(() => - //{ - // object p = context.Database.Migrate(); - // seeder(context, services); - //}); - - logger.LogInformation($"Migrated database associated with context {typeof(TContext).Name}"); - } - catch (Exception ex) - { - logger.LogError(ex, $"An error occurred while migrating the databases used on context {typeof(TContext).Name}"); - } - - return webHost; - - } - } -} diff --git a/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs b/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs deleted file mode 100644 index 2ba98aec..00000000 --- a/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/IResultRepository.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Resulting.Domain.SeedWork; - -namespace Resulting.Domain.AggregateModel.ResultingAggregate -{ - public interface IResultRepository : IRepository - { - Results Add(Results enrollment); - - Results Update(Results enrollment); - - Task FindByIdAsync( - Guid id, - CancellationToken cancellationToken = default); - } -} diff --git a/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs b/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs deleted file mode 100644 index 164b6ee6..00000000 --- a/src/Services/Resulting/Resulting.Domain/AggregateModel/ResultingAggregate/Results.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Resulting.Domain.SeedWork; - -namespace Resulting.Domain.AggregateModel.ResultingAggregate -{ - public class Results : Entity, IAggregateRoot - { - public Results( - string Result, - string GradeScale, - string Grade) - { - Result = !string.IsNullOrWhiteSpace(Result) ? Result - : throw new ArgumentNullException(nameof(Result)); - GradeScale = !string.IsNullOrWhiteSpace(GradeScale) ? GradeScale - : throw new ArgumentNullException(nameof(GradeScale)); - Grade = !string.IsNullOrWhiteSpace(Grade) ? Grade - : throw new ArgumentNullException(nameof(Grade)); - } - - public string Result { get; private set; } - - public string GradeScale { get; private set; } - - public string Grade { get; private set; } - - public int Number { get; private set; } - } -} diff --git a/src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj b/src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj deleted file mode 100644 index 2f002aa3..00000000 --- a/src/Services/Resulting/Resulting.Domain/Resulting.Domain.csproj +++ /dev/null @@ -1,7 +0,0 @@ - - - - net5.0 - - - diff --git a/src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs b/src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs deleted file mode 100644 index 7648a3f4..00000000 --- a/src/Services/Resulting/Resulting.Domain/SeedWork/Entity.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Resulting.Domain.SeedWork -{ - public abstract class Entity - { - public Guid Id { get; protected set; } - } -} diff --git a/src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs b/src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs deleted file mode 100644 index a14b651d..00000000 --- a/src/Services/Resulting/Resulting.Domain/SeedWork/IAggregateRoot.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Resulting.Domain.SeedWork -{ - [System.Diagnostics.CodeAnalysis.SuppressMessage( - "Design", - "CA1040:Avoid empty interfaces", - Justification = "Marker interface")] - public interface IAggregateRoot - { - } -} diff --git a/src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs b/src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs deleted file mode 100644 index c1b16d45..00000000 --- a/src/Services/Resulting/Resulting.Domain/SeedWork/IRepository.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Resulting.Domain.SeedWork -{ - [System.Diagnostics.CodeAnalysis.SuppressMessage( - "Design", - "CA1040:Avoid empty interfaces", - Justification = "Marker interface")] - public interface IRepository - where T : IAggregateRoot - { - } -} diff --git a/src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs b/src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs deleted file mode 100644 index d44fb5c1..00000000 --- a/src/Services/Resulting/Resulting.Infrastructure/Repositories/ResultingRepository.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Resulting.Domain.AggregateModel.ResultingAggregate; - -namespace Resulting.Infrastructure.Repositories -{ - public class ResultingRepository : IResultRepository - { - private readonly ResultingContext _context; - - public ResultingRepository(ResultingContext context) - { - _context = context ?? throw new ArgumentNullException(nameof(context)); - } - - public Results Add(Results results) - { - return _context.Resulting - .Add(results) - .Entity; - } - - public async Task FindByIdAsync( - Guid id, - CancellationToken cancellationToken = default) - { - return await _context.Resulting - .Where(e => e.Id == id) - .SingleOrDefaultAsync(cancellationToken) - .ConfigureAwait(false); - } - - public Results Update(Results results) - { - return _context.Resulting - .Update(results) - .Entity; - } - } -} diff --git a/src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj b/src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj deleted file mode 100644 index d2dd22fe..00000000 --- a/src/Services/Resulting/Resulting.Infrastructure/Resulting.Infrastructure.csproj +++ /dev/null @@ -1,19 +0,0 @@ - - - - net5.0 - - - - - - - - - - - - - - - diff --git a/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs b/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs deleted file mode 100644 index 21b93fc4..00000000 --- a/src/Services/Resulting/Resulting.Infrastructure/ResultingContext.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Design; -using Resulting.Domain.AggregateModel.ResultingAggregate; - -namespace Resulting.Infrastructure -{ - public class ResultingContext : DbContext - { - public ResultingContext(DbContextOptions options) - : base(options) - { - } - - public DbSet Resulting { get; set; } = default!; - } - - /// - /// Helper class for creating migration. To create new migration, run the - /// command from `Enrolling.Intrastructure` folder. - /// - /// $ dotnet ef migrations add name_of_migration --startup-project ../Enrolling.API. - /// - //public class ResultingContextFactory : IDesignTimeDbContextFactory - //{ - // public ResultingContext CreateDbContext(string[] args) - // { - // var optionsBuilder = new DbContextOptionsBuilder() - // .UseSqlServer("Server=.;Initial Catalog=OpenCodeFoundation.ResultingDB;Integrated Security=true"); - - // return new ResultingContext(optionsBuilder.Options); - // } - //} -} From 04f7ad61c7115dd7e35945a59c6e7b036d080fc3 Mon Sep 17 00:00:00 2001 From: shahanazdev19 Date: Sat, 3 Jul 2021 22:22:12 +0600 Subject: [PATCH 4/7] Remove eSchool solution from Master Branch --- eSchool.sln | 34 +++------------- .../Controllers/WeatherForecastController.cs | 39 ------------------- .../ResultProcessing.API/WeatherForecast.cs | 15 ------- 3 files changed, 5 insertions(+), 83 deletions(-) delete mode 100644 src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs delete mode 100644 src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs diff --git a/eSchool.sln b/eSchool.sln index 1993c4ba..ebe59606 100644 --- a/eSchool.sln +++ b/eSchool.sln @@ -27,23 +27,19 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WebStatus", "src\Web\WebSta EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Libraries", "Libraries", "{74511F4E-FF9D-42C4-9531-A75C61270B73}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry", "src\Libraries\OpenTelemetry\OpenTelemetry.csproj", "{7B410F3B-36E0-4853-9B4E-41D0CC2865B5}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiGateways", "ApiGateways", "{256317ED-A2C8-48A0-9C6E-D6EB1F7D0BE0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "eSchool.GraphQL", "src\ApiGateways\eSchool.GraphQL\eSchool.GraphQL.csproj", "{4053591A-1C1A-4A81-8496-F2FF7EAB2D5C}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Frontend.Blazor", "Frontend.Blazor", "{0C00A596-0FE3-4FA6-B54B-FE2BE83371EF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Client", "src\Web\Frontend.Blazor\Frontend.Blazor.Client\Frontend.Blazor.Client.csproj", "{53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Client", "src\Web\Frontend.Blazor\Frontend.Blazor.Client\Frontend.Blazor.Client.csproj", "{53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Server", "src\Web\Frontend.Blazor\Frontend.Blazor.Server\Frontend.Blazor.Server.csproj", "{3BABD4D9-56A1-4BA3-B30C-30E6765AB389}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Server", "src\Web\Frontend.Blazor\Frontend.Blazor.Server\Frontend.Blazor.Server.csproj", "{3BABD4D9-56A1-4BA3-B30C-30E6765AB389}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" -EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ResultProcessing", "ResultProcessing", "{42B5BC23-92AF-4E3A-8C52-788355924951}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ResultProcessing.API", "src\Services\ResultProcessing\ResultProcessing.API\ResultProcessing.API.csproj", "{888AD861-8D13-497D-BCCE-E162A0DB4650}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Frontend.Blazor.Shared", "src\Web\Frontend.Blazor\Frontend.Blazor.Shared\Frontend.Blazor.Shared.csproj", "{4EB86635-CF79-4D15-909E-C41C98B0B586}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "CertificateProcessing", "CertificateProcessing", "{38032F91-9580-44DC-AF92-0F562D7126F8}" EndProject @@ -203,20 +199,6 @@ Global {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x64.Build.0 = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.ActiveCfg = Release|Any CPU {4EB86635-CF79-4D15-909E-C41C98B0B586}.Release|x86.Build.0 = Release|Any CPU -<<<<<<< HEAD - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|Any CPU.Build.0 = Debug|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x64.ActiveCfg = Debug|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x64.Build.0 = Debug|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x86.ActiveCfg = Debug|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Debug|x86.Build.0 = Debug|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|Any CPU.ActiveCfg = Release|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|Any CPU.Build.0 = Release|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x64.ActiveCfg = Release|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x64.Build.0 = Release|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x86.ActiveCfg = Release|Any CPU - {888AD861-8D13-497D-BCCE-E162A0DB4650}.Release|x86.Build.0 = Release|Any CPU -======= {7C7B638F-A1E9-4908-91DD-4060E45F2CE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {7C7B638F-A1E9-4908-91DD-4060E45F2CE5}.Debug|Any CPU.Build.0 = Debug|Any CPU {7C7B638F-A1E9-4908-91DD-4060E45F2CE5}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -229,7 +211,6 @@ Global {7C7B638F-A1E9-4908-91DD-4060E45F2CE5}.Release|x64.Build.0 = Release|Any CPU {7C7B638F-A1E9-4908-91DD-4060E45F2CE5}.Release|x86.ActiveCfg = Release|Any CPU {7C7B638F-A1E9-4908-91DD-4060E45F2CE5}.Release|x86.Build.0 = Release|Any CPU ->>>>>>> a9ac3fcd55fe1ffe6622486bd2a2d7d8dc43d5c4 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -252,13 +233,8 @@ Global {53F4E6F9-6B91-45F9-97F9-F6EFA0EBEFCE} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {3BABD4D9-56A1-4BA3-B30C-30E6765AB389} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} {4EB86635-CF79-4D15-909E-C41C98B0B586} = {0C00A596-0FE3-4FA6-B54B-FE2BE83371EF} -<<<<<<< HEAD - {42B5BC23-92AF-4E3A-8C52-788355924951} = {1C120673-72F4-4679-AC4C-68286E9091A5} - {888AD861-8D13-497D-BCCE-E162A0DB4650} = {42B5BC23-92AF-4E3A-8C52-788355924951} -======= {38032F91-9580-44DC-AF92-0F562D7126F8} = {1C120673-72F4-4679-AC4C-68286E9091A5} {7C7B638F-A1E9-4908-91DD-4060E45F2CE5} = {38032F91-9580-44DC-AF92-0F562D7126F8} ->>>>>>> a9ac3fcd55fe1ffe6622486bd2a2d7d8dc43d5c4 EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {E418719F-3193-403E-AF58-9BE9F94FD8BE} diff --git a/src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs b/src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs deleted file mode 100644 index 18635dbf..00000000 --- a/src/Services/ResultProcessing/ResultProcessing.API/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Logging; - -namespace ResultProcessing.API.Controllers -{ - [ApiController] - [Route("[controller]")] - public class WeatherForecastController : ControllerBase - { - private static readonly string[] Summaries = new[] - { - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" - }; - - private readonly ILogger _logger; - - public WeatherForecastController(ILogger logger) - { - _logger = logger; - } - - [HttpGet] - public IEnumerable Get() - { - var rng = new Random(); - return Enumerable.Range(1, 5).Select(index => new WeatherForecast - { - Date = DateTime.Now.AddDays(index), - TemperatureC = rng.Next(-20, 55), - Summary = Summaries[rng.Next(Summaries.Length)] - }) - .ToArray(); - } - } -} diff --git a/src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs b/src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs deleted file mode 100644 index b8559deb..00000000 --- a/src/Services/ResultProcessing/ResultProcessing.API/WeatherForecast.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; - -namespace ResultProcessing.API -{ - public class WeatherForecast - { - public DateTime Date { get; set; } - - public int TemperatureC { get; set; } - - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); - - public string Summary { get; set; } - } -} From 81c5e37c3594d9b85be2d1443a68380a12edd752 Mon Sep 17 00:00:00 2001 From: shahanazdev19 Date: Sat, 3 Jul 2021 22:25:14 +0600 Subject: [PATCH 5/7] Remove HTTPS redirection from startup.cs --- src/Services/ResultProcessing/ResultProcessing.API/Startup.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs b/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs index 3eb7f1bd..8cb2d22f 100644 --- a/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs +++ b/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs @@ -37,8 +37,6 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) app.UseSwagger(); app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ResultProcessing.API v1")); - app.UseHttpsRedirection(); - app.UseRouting(); app.UseAuthorization(); From 8e22526d566d0d72d987f1d6b2089d8aec58ee7a Mon Sep 17 00:00:00 2001 From: shahanazdev19 Date: Sat, 4 Sep 2021 16:15:20 +0600 Subject: [PATCH 6/7] Serlog and SEQ applied --- .../ResultProcessing.API/Program.cs | 57 ++++++++++++++++++- .../ResultProcessing.API.csproj | 2 + .../ResultProcessing.API/Startup.cs | 22 +++---- 3 files changed, 68 insertions(+), 13 deletions(-) diff --git a/src/Services/ResultProcessing/ResultProcessing.API/Program.cs b/src/Services/ResultProcessing/ResultProcessing.API/Program.cs index 171e8e0e..9b9056b9 100644 --- a/src/Services/ResultProcessing/ResultProcessing.API/Program.cs +++ b/src/Services/ResultProcessing/ResultProcessing.API/Program.cs @@ -10,17 +10,70 @@ namespace ResultProcessing.API { public class Program - { + { + public static readonly string Namespace = typeof(Program).Namespace!; + public static readonly string AppName = Namespace.Substring(Namespace.LastIndexOf('.', Namespace.LastIndexOf('.') - 1) + 1); + + [System.Diagnostics.CodeAnalysis.SuppressMessage( + "Design", + "CA1031:Do not catch general exception types", + Justification = "Top level all exception catcher")] public static void Main(string[] args) { CreateHostBuilder(args).Build().Run(); + Activity.DefaultIdFormat = ActivityIdFormat.W3C; + + var configuration = GetConfiguration(); + + Log.Logger = CreateSerilogLogger(configuration); + try + { + Log.Information("Configuring web host ({ApplicationContext})...", AppName); + CreateHostBuilder(args).Build().Run(); + + return 0; + } + catch (Exception ex) + { + Log.Fatal(ex, "Host terminated unexpectedly"); + return 1; + } + finally + { + Log.CloseAndFlush(); + } } - public static IHostBuilder CreateHostBuilder(string[] args) => + public static IHostBuilder CreateHostBuilder(IConfiguration configuration,string[] args) => Host.CreateDefaultBuilder(args) .ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup(); + webBuilder.UseConfiguration(configuration); + webBuilder.UseSerilog(); }); + + private static ILogger CreateSerilogLogger(IConfiguration configuration) + { + return new LoggerConfiguration() + .MinimumLevel.Verbose() + .Enrich.WithProperty("ApplicationContext", AppName) + .Enrich.FromLogContext() + .Enrich.WithSpan() + .WriteTo.Console() + .WriteTo.Seq("http://seq") + .ReadFrom.Configuration(configuration) + .CreateLogger(); + } + + private static IConfiguration GetConfiguration() + { + var builder = new ConfigurationBuilder() + .SetBasePath(Directory.GetCurrentDirectory()) + .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) + .AddEnvironmentVariables(); + + return builder.Build(); + } } } diff --git a/src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj b/src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj index 28847161..716d4374 100644 --- a/src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj +++ b/src/Services/ResultProcessing/ResultProcessing.API/ResultProcessing.API.csproj @@ -5,6 +5,8 @@ + + diff --git a/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs b/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs index 8cb2d22f..223a647a 100644 --- a/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs +++ b/src/Services/ResultProcessing/ResultProcessing.API/Startup.cs @@ -28,23 +28,23 @@ public void ConfigureServices(IServiceCollection services) } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory) { + var pathBase = Configuration["PATH_BASE"]; + if (!string.IsNullOrEmpty(pathBase)) + { + loggerFactory.CreateLogger().LogInformation("Using PATH BASE '{pathBase}'", pathBase); + app.UsePathBase(pathBase); + } + if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); + } + app.UseSerilogRequestLogging(); app.UseSwagger(); - app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ResultProcessing.API v1")); - - app.UseRouting(); - - app.UseAuthorization(); - - app.UseEndpoints(endpoints => - { - endpoints.MapControllers(); - }); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "ExamManagement.API v1")); } } } From 8ade6c046770196983e2467b59057846624c5f1d Mon Sep 17 00:00:00 2001 From: shahanazdev19 Date: Sat, 4 Sep 2021 21:33:02 +0600 Subject: [PATCH 7/7] appsetting.jsonFilechanged --- .../ResultProcessing.API/appsettings.Development.json | 9 --------- .../ResultProcessing.API/appsettings.json | 11 +++++++---- 2 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 src/Services/ResultProcessing/ResultProcessing.API/appsettings.Development.json diff --git a/src/Services/ResultProcessing/ResultProcessing.API/appsettings.Development.json b/src/Services/ResultProcessing/ResultProcessing.API/appsettings.Development.json deleted file mode 100644 index 8983e0fc..00000000 --- a/src/Services/ResultProcessing/ResultProcessing.API/appsettings.Development.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "Logging": { - "LogLevel": { - "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" - } - } -} diff --git a/src/Services/ResultProcessing/ResultProcessing.API/appsettings.json b/src/Services/ResultProcessing/ResultProcessing.API/appsettings.json index d9d9a9bf..bb6dc2e6 100644 --- a/src/Services/ResultProcessing/ResultProcessing.API/appsettings.json +++ b/src/Services/ResultProcessing/ResultProcessing.API/appsettings.json @@ -1,9 +1,12 @@ { - "Logging": { - "LogLevel": { + "Serilog": { + "MinimumLevel": { "Default": "Information", - "Microsoft": "Warning", - "Microsoft.Hosting.Lifetime": "Information" + "Override": { + "Microsoft": "Warning", + "OpenCodeFoundation": "Information", + "System": "Warning" + } } }, "AllowedHosts": "*"