Skip to content

Commit

Permalink
Merge pull request #25 from Grinderofl/users/nero/netcore31
Browse files Browse the repository at this point in the history
Adds ASP.NET Core 3.1 support, re #24
  • Loading branch information
Grinderofl authored Aug 20, 2020
2 parents ae98827 + 20eb757 commit 4305414
Show file tree
Hide file tree
Showing 12 changed files with 140 additions and 44 deletions.
2 changes: 0 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ Setup<Configuration>(Configuration.Create);
#load ".cake/Restore-DotNetCore.cake"
#load ".cake/Build-DotNetCore.cake"
#load ".cake/Test-DotNetCore.cake"
#load ".cake/Publish-Zip-DotNetCore.cake"
#load ".cake/Publish-Pack-DotNetCore.cake"
#load ".cake/Artifacts-DotNetCore-Ef.cake"
// -------------

Task("Restore:DotNetCore:Tools")
Expand Down
45 changes: 39 additions & 6 deletions samples/Storm.Formification.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
#if NETCOREAPP3_1
using Microsoft.Extensions.Hosting;
#endif
using Storm.Formification.Web.Infrastructure;
using Storm.Formification.Web.Forms;
using static Storm.Formification.Core.Forms;
Expand Down Expand Up @@ -36,7 +39,14 @@ public void ConfigureServices(IServiceCollection services)

services.AddRouting(o => { o.LowercaseUrls = true; });

var formAssemblies = new[] { Assembly.GetEntryAssembly() }.ToArray();
var formAssemblies = new[]
{
#if NETCOREAPP3_1
Assembly.GetEntryAssembly()!
#else
Assembly.GetEntryAssembly()
#endif
}.ToArray();

services.AddMediatR(typeof(Startup));
services.AddMemoryCache();
Expand All @@ -45,13 +55,17 @@ public void ConfigureServices(IServiceCollection services)
.AddMvc()
.ConfigureForms(formAssemblies).EnableFormsController(formAssemblies)
.AddFluentValidation(c => c.RegisterValidatorsFromAssemblyContaining<Startup>())
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
.SetCompatibilityVersion(CompatibilityVersion.Latest);

services.AddHttpClient();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
#if NETCOREAPP3_1
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
#else
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
#endif
{
if (env.IsDevelopment())
{
Expand All @@ -68,17 +82,36 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseStaticFiles();
app.UseCookiePolicy();

app.UseMvc(routes =>

#if NETCOREAPP3_1
app.UseRouting();
app.UseEndpoints(endpoints =>
{
routes.MapAreaRoute(
endpoints.MapAreaControllerRoute(
name: "forms",
areaName: "forms",
template: "{controller}/{action=Index}/{id?}");
pattern: "{controller}/{action=Index}/{id?}",
areaName: "forms");

endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

endpoints.MapRazorPages();
});
#else
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");

routes.MapAreaRoute(
name: "forms",
areaName: "forms",
template: "{controller}/{action=Index}/{id?}"
);
});
#endif
}
}
}
23 changes: 15 additions & 8 deletions samples/Storm.Formification.Web/Storm.Formification.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,18 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.2</TargetFrameworks>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation" Version="8.4.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="8.4.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="8.4.0" />
<PackageReference Include="Humanizer.Core.uk" Version="2.6.2" />
<PackageReference Include="MediatR" Version="7.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="FluentValidation" Version="9.0.1" />
<PackageReference Include="FluentValidation.AspNetCore" Version="9.0.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="9.0.1" />
<PackageReference Include="Humanizer.Core.uk" Version="2.8.26" />
<PackageReference Include="MediatR" Version="8.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
Expand All @@ -25,7 +32,7 @@

<ItemGroup>
<ProjectReference Include="..\..\src\Storm.Formification.Core\Storm.Formification.Core.csproj" />
<ProjectReference Include="..\..\src\Storm.Formification.Bootstrap4\Storm.Formification.Bootstrap4.csproj" />
<ProjectReference Include="..\..\src\Storm.Formification.Bootstrap4\Storm.Formification.Bootstrap4.csproj" PrivateAssets="All" />
<ProjectReference Include="..\..\src\Storm.Formification.TagHelpers\Storm.Formification.TagHelpers.csproj" />
</ItemGroup>

Expand Down
30 changes: 29 additions & 1 deletion samples/Storm.Formification.WebWithDb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using Storm.Formification.WebWithDb.Data;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
#if NETCOREAPP3_1
using Microsoft.Extensions.Hosting;
#endif
using Storm.Formification.Core;
using MediatR;
using static Storm.Formification.Core.Forms;
Expand Down Expand Up @@ -41,14 +44,24 @@ public void ConfigureServices(IServiceCollection services)
});

services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddDefaultIdentity<IdentityUser>().AddDefaultUI(UIFramework.Bootstrap4).AddEntityFrameworkStores<ApplicationDbContext>();
services.AddDefaultIdentity<IdentityUser>()
#if NETCOREAPP3_1
.AddDefaultUI()
#else
.AddDefaultUI(UIFramework.Bootstrap4)
#endif
.AddEntityFrameworkStores<ApplicationDbContext>();

services.AddMediatR(typeof(Startup).Assembly);

services.AddMvc()
.ConfigureForms(typeof(Startup).Assembly)
.EnableFormsController(typeof(Startup).Assembly)
#if NETCOREAPP3_1
.SetCompatibilityVersion(CompatibilityVersion.Latest);
#else
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
#endif

services.AddHttpContextAccessor();

Expand All @@ -57,7 +70,11 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
#if NETCOREAPP3_1
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
#else
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
#endif
{
if (env.IsDevelopment())
{
Expand All @@ -77,12 +94,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)

app.UseAuthentication();

#if NETCOREAPP3_1
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
#else
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
#endif
}
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netcoreapp2.2</TargetFrameworks>
<UserSecretsId>aspnet-Storm.Formification.WebWithDb-375EEF6A-E5F2-4E2B-BBD1-3847959D451F</UserSecretsId>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<IsPackable>false</IsPackable>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="MediatR" Version="7.0.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="MediatR" Version="8.1.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="8.1.0" />
<PackageReference Include="WindowsAzure.Storage" Version="9.3.3" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.1.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.6" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Storm.Formification.Core\Storm.Formification.Core.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,29 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<Description>Formification is a library that leverages features of AspNetCore Mvc to allow the creation of simple data input forms</Description>
<PackageIcon>storm-id-logo.png</PackageIcon>
<PackageIconUrl />
</PropertyGroup>

<ItemGroup>
<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
</PropertyGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1'">
<Content Remove="_Imports.razor" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Storm.Formification.Core\Storm.Formification.Core.csproj" />
<ProjectReference Include="..\Storm.Formification.TagHelpers\Storm.Formification.TagHelpers.csproj" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div class="col-md-8 col-lg-6 form-horziontal">
<form method="post" enctype="multipart/form-data" asp-antiforgery="true" asp-route-id="@ViewData?["id"]">
<form method="post" enctype="multipart/form-data" asp-antiforgery="true" asp-route-id="@(ViewData?["id"])">
@Html.RenderFormForModel()
<div class="form-row mt-3">
<input type="submit" value="Submit" />
Expand Down
1 change: 1 addition & 0 deletions src/Storm.Formification.Bootstrap4/_Imports.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@using Microsoft.AspNetCore.Components.Web
11 changes: 9 additions & 2 deletions src/Storm.Formification.Core/Storm.Formification.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<Description>Formification is a library that leverages features of AspNetCore Mvc to allow the creation of simple data input forms</Description>
<PackageIcon>storm-id-logo.png</PackageIcon>
<PackageIconUrl />
</PropertyGroup>

<ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Humanizer.Core.uk" Version="2.6.2" />
<None Include="storm-id-logo.png">
<Pack>True</Pack>
Expand Down
14 changes: 2 additions & 12 deletions src/Storm.Formification.TagHelpers/HintLabelTagHelper.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
namespace Storm.Formification.TagHelpers
{
using Storm.Formification.Core.Infrastructure;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal;
using Microsoft.AspNetCore.Razor.TagHelpers;

public class HintLabelTagHelper : TagHelper
{
private readonly IModelMetadataProvider modelMetadataProvider;

public HintLabelTagHelper(IModelMetadataProvider modelMetadataProvider)
{
this.modelMetadataProvider = modelMetadataProvider;
}

[HtmlAttributeName("asp-for")]
public ModelExpression? For { get; set; }

Expand All @@ -27,10 +18,9 @@ public override void Process(TagHelperContext context, TagHelperOutput output)
{
if(For != null && ViewContext != null)
{
var modelExplorer = ExpressionMetadataProvider.FromStringExpression(For.Name, ViewContext.ViewData, modelMetadataProvider);
if (modelExplorer.Metadata.AdditionalValues.ContainsKey(HintLabelAttribute.HintLabelKey))
if (For.Metadata.AdditionalValues.ContainsKey(HintLabelAttribute.HintLabelKey))
{
var hintLabelValue = modelExplorer.Metadata.AdditionalValues[HintLabelAttribute.HintLabelKey].ToString();
var hintLabelValue = For.Metadata.AdditionalValues[HintLabelAttribute.HintLabelKey].ToString();
if (!string.IsNullOrWhiteSpace(hintLabelValue))
{
output.TagName = "span";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<TargetFrameworks>netcoreapp3.1;netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<Description>Formification is a library that leverages features of AspNetCore Mvc to allow the creation of simple data input forms</Description>
<PackageIcon>storm-id-logo.png</PackageIcon>
<PackageIconUrl />
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Storm.Formification.Core\Storm.Formification.Core.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'netcoreapp3.1'">
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
<None Include="storm-id-logo.png">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down

0 comments on commit 4305414

Please sign in to comment.