Skip to content

Commit

Permalink
Merge branch 'master' into Feature/MinimalAPI
Browse files Browse the repository at this point in the history
  • Loading branch information
moattarwork committed Aug 23, 2024
2 parents 89ef2e3 + bc3a429 commit e40bcf9
Show file tree
Hide file tree
Showing 45 changed files with 271 additions and 244 deletions.
2 changes: 1 addition & 1 deletion GitVersion.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
next-version: 1.0.2
next-version: 2.2.0
mode: Mainline
major-version-bump-message: '\+semver:\s?(breaking|major)'
minor-version-bump-message: '\+semver:\s?(feature|minor)'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>12</LangVersion>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.DependencyInjection\LittleBlocks.DependencyInjection.csproj" />
<ProjectReference Include="..\LittleBlocks.AspNetCore.Bootstrap\LittleBlocks.AspNetCore.Bootstrap.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<None Update="LittleBlocks.AspNetCore.Bootstrap.UnitTests.xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<PropertyGroup>
<LangVersion>
12
</LangVersion>
<TargetFramework>
net8.0
</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>
all
</PrivateAssets>
<IncludeAssets>
runtime; build; native; contentfiles; analyzers; buildtransitive
</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.DependencyInjection\LittleBlocks.DependencyInjection.csproj" />
<ProjectReference Include="..\LittleBlocks.AspNetCore.Bootstrap\LittleBlocks.AspNetCore.Bootstrap.csproj" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
<ItemGroup>
<None Update="LittleBlocks.AspNetCore.Bootstrap.UnitTests.xunit.runner.json">
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
19 changes: 7 additions & 12 deletions src/LittleBlocks.AspNetCore.Bootstrap/ApiPipelineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,14 @@

namespace LittleBlocks.AspNetCore.Bootstrap;

public sealed class ApiPipelineOptions
public sealed class ApiPipelineOptions(
IConfiguration configuration,
IHostEnvironment environment,
ILoggerFactory loggerFactory)
{
public ApiPipelineOptions(IConfiguration configuration, IHostEnvironment environment,
ILoggerFactory loggerFactory)
{
Configuration = configuration ?? throw new ArgumentNullException(nameof(configuration));
Environment = environment ?? throw new ArgumentNullException(nameof(environment));
LoggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
}

public IConfiguration Configuration { get; }
public IHostEnvironment Environment { get; }
public ILoggerFactory LoggerFactory { get; }
public IConfiguration Configuration { get; } = configuration ?? throw new ArgumentNullException(nameof(configuration));
public IHostEnvironment Environment { get; } = environment ?? throw new ArgumentNullException(nameof(environment));
public ILoggerFactory LoggerFactory { get; } = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory));
public Action PostAuthenticationConfigure { get; } = null;
public Action<IEndpointRouteBuilder> PreEndPointsConfigure { get; } = null;
public Action<IEndpointRouteBuilder> PostEndPointsConfigure { get; } = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,38 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

using Serilog;

namespace LittleBlocks.AspNetCore.Bootstrap;

public static class ApplicationBuilderExtensions
{
public static void UseDefaultApiPipeline(this IApplicationBuilder app,
IConfiguration configuration,
IWebHostEnvironment env,
IHostApplicationLifetime lifetime,
ILoggerFactory loggerFactory)
{
if (app == null) throw new ArgumentNullException(nameof(app));
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
if (env == null) throw new ArgumentNullException(nameof(env));
if (loggerFactory == null) throw new ArgumentNullException(nameof(loggerFactory));
ArgumentNullException.ThrowIfNull(lifetime);
ArgumentNullException.ThrowIfNull(app);
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(env);
ArgumentNullException.ThrowIfNull(loggerFactory);

InitiateFlushOutstandingOperations(lifetime);
var options = new ApiPipelineOptions(configuration, env, loggerFactory);
app.UseDefaultApiPipeline(options);
}

public static void UseDefaultApiPipeline(this IApplicationBuilder app, ApiPipelineOptions options)
private static void InitiateFlushOutstandingOperations(IHostApplicationLifetime lifetime)
{
lifetime.ApplicationStopped.Register(Log.CloseAndFlush);
}

private static void UseDefaultApiPipeline(this IApplicationBuilder app, ApiPipelineOptions options)
{
if (app == null) throw new ArgumentNullException(nameof(app));
if (options == null) throw new ArgumentNullException(nameof(options));
ArgumentNullException.ThrowIfNull(app);
ArgumentNullException.ThrowIfNull(options);

var appInfo = options.Configuration.GetApplicationInfo();
var authOptions = options.Configuration.GetAuthOptions();
Expand Down Expand Up @@ -87,8 +97,8 @@ public static void UseDefaultApiPipeline(this IApplicationBuilder app, ApiPipeli

public static void UseStartPage(this IEndpointRouteBuilder endpoints, string applicationName)
{
if (endpoints == null) throw new ArgumentNullException(nameof(endpoints));
if (applicationName == null) throw new ArgumentNullException(nameof(applicationName));
ArgumentNullException.ThrowIfNull(endpoints);
ArgumentNullException.ThrowIfNull(applicationName);

endpoints.MapGet("/", context =>
{
Expand Down Expand Up @@ -128,6 +138,6 @@ private static string LoadStartPageFromEmbeddedResource(string applicationName)
private static void LogResolvedEnvironment(IHostEnvironment env, ILoggerFactory loggerFactory)
{
var log = loggerFactory.CreateLogger("Startup");
log.LogInformation($"Application is started in '{env.EnvironmentName.ToUpper()}' environment ...");
log.LogInformation($"{nameof(Application)} is started in '{env.EnvironmentName.ToUpper()}' environment ...");
}
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,56 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Description>Allows easy bootstrapping of .NET Core App's</Description>
<Authors>Mohammad Moattar; Aurimas Gecas</Authors>
<Company>LittleBlocks</Company>
<PackageProjectUrl>http://github.com/LittleBlocks/LittleBlocks.API</PackageProjectUrl>
<RepositoryUrl>https://github.com/LittleBlocks/LittleBlocks.API</RepositoryUrl>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
<Version>1.0.0</Version>
<LangVersion>12</LangVersion>
<OutputType>Library</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.AspNetCore\LittleBlocks.AspNetCore.csproj" />
<ProjectReference Include="..\LittleBlocks.Bootstrap\LittleBlocks.Bootstrap.csproj" />
<ProjectReference Include="..\LittleBlocks.Configurations\LittleBlocks.Configurations.csproj" />
<ProjectReference Include="..\LittleBlocks.ExceptionHandling\LittleBlocks.ExceptionHandling.csproj" />
<ProjectReference Include="..\LittleBlocks.RestEase\LittleBlocks.RestEase.csproj" />
<ProjectReference Include="..\LittleBlocks.DependencyInjection\LittleBlocks.DependencyInjection.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Templates\home.html" />
<EmbeddedResource Include="Templates\home.html" />
</ItemGroup>
<PropertyGroup>
<TargetFramework>
net8.0
</TargetFramework>
<GeneratePackageOnBuild>
True
</GeneratePackageOnBuild>
<Description>
Allows easy bootstrapping of .NET Core App's
</Description>
<Authors>
Mohammad Moattar; Aurimas Gecas
</Authors>
<Company>
LittleBlocks
</Company>
<PackageProjectUrl>
http://github.com/LittleBlocks/LittleBlocks.API
</PackageProjectUrl>
<RepositoryUrl>
https://github.com/LittleBlocks/LittleBlocks.API
</RepositoryUrl>
<GenerateAssemblyVersionAttribute>
false
</GenerateAssemblyVersionAttribute>
<Version>
1.0.0
</Version>
<LangVersion>
12
</LangVersion>
<OutputType>
Library
</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AspNetCore.HealthChecks.UI.Client" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink.Loader" Version="14.1.0" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.AspNetCore\LittleBlocks.AspNetCore.csproj" />
<ProjectReference Include="..\LittleBlocks.Bootstrap\LittleBlocks.Bootstrap.csproj" />
<ProjectReference Include="..\LittleBlocks.Configurations\LittleBlocks.Configurations.csproj" />
<ProjectReference Include="..\LittleBlocks.ExceptionHandling\LittleBlocks.ExceptionHandling.csproj" />
<ProjectReference Include="..\LittleBlocks.RestEase\LittleBlocks.RestEase.csproj" />
<ProjectReference Include="..\LittleBlocks.DependencyInjection\LittleBlocks.DependencyInjection.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Templates\home.html" />
<EmbeddedResource Include="Templates\home.html" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<LangVersion>12</LangVersion>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.6.6" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\LittleBlocks.AspNetCore\LittleBlocks.AspNetCore.csproj" />
<ProjectReference Include="..\LittleBlocks.Testing\LittleBlocks.Testing.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="LittleBlocks.AspNetCore.UnitTests.xunit.runner.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>

<PropertyGroup>
<LangVersion>
12
</LangVersion>
<TargetFramework>
net8.0
</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NSubstitute" Version="5.1.0" />
<PackageReference Include="System.ComponentModel.TypeConverter" Version="4.3.0" />
<PackageReference Include="xunit" Version="2.8.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.1">
<PrivateAssets>
all
</PrivateAssets>
<IncludeAssets>
runtime; build; native; contentfiles; analyzers; buildtransitive
</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.AspNetCore\LittleBlocks.AspNetCore.csproj" />
<ProjectReference Include="..\LittleBlocks.Testing\LittleBlocks.Testing.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="LittleBlocks.AspNetCore.UnitTests.xunit.runner.json">
<CopyToOutputDirectory>
PreserveNewest
</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/LittleBlocks.AspNetCore/HostAsWeb.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ private static IWebHost Build<TStartup>(
where TStartup : class
{
ArgumentNullException.ThrowIfNull(loggerConfigure);

var host = WebHost
.CreateDefaultBuilder(args)
.UseStartup<TStartup>()
Expand All @@ -39,7 +39,7 @@ private static IWebHost Build<TStartup>(
})
.ConfigureServices((context, services) =>
{
loggerConfigure(new LoggerBuilder(context.HostingEnvironment, context.Configuration, new LoggerConfiguration())).Build<TStartup>();
loggerConfigure(new LoggerBuilder(services, context.HostingEnvironment, context.Configuration)).Build<TStartup>();
})
.Build();

Expand Down
26 changes: 11 additions & 15 deletions src/LittleBlocks.AspNetCore/LittleBlocks.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,24 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.1.1" />
<PackageReference Include="Microsoft.FeatureManagement.AspNetCore" Version="3.4.0" />
<PackageReference Include="Foil" Version="1.0.37" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="8.0.6" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="RestEase" Version="1.6.4" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog" Version="4.0.0" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.2" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Enrichers.Process" Version="3.0.0" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="8.0.1" />
<PackageReference Include="Serilog.Sinks.Literate" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Swashbuckle.AspNetCore.ReDoc" Version="6.5.0" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="8.0.0" />
<PackageReference Include="CorrelationId" Version="3.0.1"/>
<PackageReference Include="MicroElements.Swashbuckle.FluentValidation" Version="6.0.0"/>
<PackageReference Include="GlobalExceptionHandler" Version="4.0.2"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
<PackageReference Include="AspNetCore.HealthChecks.Uris" Version="8.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LittleBlocks.Configurations\LittleBlocks.Configurations.csproj" />
Expand Down
Loading

0 comments on commit e40bcf9

Please sign in to comment.