Skip to content

Commit

Permalink
Merge pull request #123 from ChrisPulman/UpdateWebBuilder
Browse files Browse the repository at this point in the history
Add WebBuilder Config
  • Loading branch information
ChrisPulman authored Apr 11, 2024
2 parents 3c7e0ea + 39f6d46 commit 7721f49
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('net8')) ">
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,26 @@ public static IHostBuilder UseWebHostServices(this IHostBuilder hostBuilder, Act
.Configure(app => app.Run(async (_) => await Task.CompletedTask)) // Dummy app.Run to prevent 'No application service provider was found' error.
.ConfigureServices((context, services) => configureServices(context, services)));
}

/// <summary>
/// Uses the web host services.
/// </summary>
/// <param name="hostBuilder">The host builder.</param>
/// <param name="configureServices">The configure services.</param>
/// <param name="configureWebHost">The configure web host.</param>
/// <param name="validateScopes">if set to <c>true</c> [validate scopes].</param>
/// <returns>
/// IHostBuilder.
/// </returns>
/// <exception cref="System.ArgumentNullException">hostBuilder.</exception>
public static IHostBuilder UseWebHostServices(this IHostBuilder hostBuilder, Action<WebHostBuilderContext, IServiceCollection> configureServices, Func<IWebHostBuilder, IWebHostBuilder> configureWebHost, bool validateScopes = false)
{
ArgumentNullException.ThrowIfNull(hostBuilder);

return hostBuilder.ConfigureWebHostDefaults(webBuilder =>
configureWebHost(webBuilder)
.UseDefaultServiceProvider(options => options.ValidateScopes = validateScopes)
.Configure(app => app.Run(async (_) => await Task.CompletedTask)) // Dummy app.Run to prevent 'No application service provider was found' error.
.ConfigureServices((context, services) => configureServices(context, services)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@
</ItemGroup>

<ItemGroup Condition=" $(TargetFramework.StartsWith('net8')) ">
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,30 @@ public static IHostBuilder UseWebHostServices(this IHostBuilder hostBuilder, Act
ArgumentNullException.ThrowIfNull(hostBuilder);

return hostBuilder.ConfigureWebHostDefaults(webBuilder =>
webBuilder.UseDefaultServiceProvider(options => options.ValidateScopes = validateScopes)
.Configure(app => app.Run(async (_) => await Task.CompletedTask)) // Dummy app.Run to prevent 'No application service provider was found' error.
.ConfigureServices((context, services) => configureServices(context, services)));
webBuilder.UseDefaultServiceProvider(options => options.ValidateScopes = validateScopes)
.Configure(app => app.Run(async (_) => await Task.CompletedTask)) // Dummy app.Run to prevent 'No application service provider was found' error.
.ConfigureServices((context, services) => configureServices(context, services)));
}

/// <summary>
/// Uses the web host services.
/// </summary>
/// <param name="hostBuilder">The host builder.</param>
/// <param name="configureServices">The configure services.</param>
/// <param name="configureWebHost">The configure web host.</param>
/// <param name="validateScopes">if set to <c>true</c> [validate scopes].</param>
/// <returns>
/// IHostBuilder.
/// </returns>
/// <exception cref="System.ArgumentNullException">hostBuilder.</exception>
public static IHostBuilder UseWebHostServices(this IHostBuilder hostBuilder, Action<WebHostBuilderContext, IServiceCollection> configureServices, Func<IWebHostBuilder, IWebHostBuilder> configureWebHost, bool validateScopes = false)
{
ArgumentNullException.ThrowIfNull(hostBuilder);

return hostBuilder.ConfigureWebHostDefaults(webBuilder =>
configureWebHost(webBuilder)
.UseDefaultServiceProvider(options => options.ValidateScopes = validateScopes)
.Configure(app => app.Run(async (_) => await Task.CompletedTask)) // Dummy app.Run to prevent 'No application service provider was found' error.
.ConfigureServices((context, services) => configureServices(context, services)));
}
}
2 changes: 1 addition & 1 deletion version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "1.2",
"version": "1.3",
"publicReleaseRefSpec": [
"^refs/heads/main$",
"^refs/heads/master$",
Expand Down

0 comments on commit 7721f49

Please sign in to comment.