Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sample application to ASP.NET Core 3.1 #16

Merged
merged 2 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
- name: Setup .NET Core Build Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: '2.2.x'
dotnet-version: '3.1.x'
- name: Build package
run: dotnet build --configuration Release
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Setup .NET Core Build Environment
uses: actions/setup-dotnet@v1
with:
dotnet-version: '2.2.x'
dotnet-version: '3.1.x'
- name: Build packages
run: dotnet build --configuration Release
- name: Pack NuGet packages
Expand Down
24 changes: 8 additions & 16 deletions DataTables.NetStandard.Sample/DataTables.NetStandard.Sample.csproj
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.2</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<TargetFramework>netcoreapp3.1</TargetFramework>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
</PropertyGroup>

<ItemGroup>
<None Remove="Views\DataTables\Person\Action.twig" />
</ItemGroup>

<ItemGroup>
<Content Include="Views\DataTables\Person\Action.twig">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>


<ItemGroup>
<PackageReference Include="AutoMapper" Version="10.0.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0" />
<PackageReference Include="DataTables.NetStandard.TemplateMapper" Version="0.2.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.2.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.6" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\DataTables.NetStandard\DataTables.NetStandard.csproj" />
</ItemGroup>

<ItemGroup>
<Content Include="Views\DataTables\Person\Action.twig">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>

</Project>

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// <auto-generated />
using System;
using DataTables.NetStandard.Sample;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;

namespace DataTables.NetStandard.Sample.Migrations
{
Expand Down
28 changes: 17 additions & 11 deletions DataTables.NetStandard.Sample/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
using DataTables.NetStandard.TemplateMapper;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.Reflection;
using Microsoft.Extensions.Hosting;

namespace DataTables.NetStandard.Sample
{
Expand All @@ -25,26 +24,31 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<SampleDbContext>(options =>
{
options.UseSqlServer("Server=(localdb)\\mssqllocaldb;Database=DataTables.NetStandard.Sample;Trusted_Connection=True;");
options.UseSqlServer(Configuration.GetConnectionString("Database"));
});

services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
services.AddControllersWithViews();

services.AddDataTablesTemplateMapper();
services.AddScoped<PersonDataTable>();

// We need to register custom services we want to use in the mapping profile.
services.AddTransient<IViewRenderService, ViewRenderService>();

// Building the service provider early to get the IViewRenderService is a hack that is necessary to get access
// to the Razor partial compiler in the DefaultMappingProfile. As the IViewRenderService depends on services
// from Microsoft.AspNetCore.Mvc.Razor, it is necessary to configure MVC with services.AddMvc() before
// configuring the Mapper like this.
services.AddAutoMapper(m =>
services.AddScoped(provider => new MapperConfiguration(config =>
{
m.AddProfile(new DefaultMappingProfile(services.BuildServiceProvider().GetService<IViewRenderService>()));
}, Assembly.GetAssembly(typeof(DefaultMappingProfile)));
config.AddProfile(new DefaultMappingProfile(provider.GetService<IViewRenderService>()));
}).CreateMapper());
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, SampleDbContext dbContext)
{
dbContext.Database.Migrate();

if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand All @@ -58,11 +62,13 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseMvc(routes =>
app.UseRouting();

app.UseEndpoints(endpoints =>
{
routes.MapRoute(
endpoints.MapControllerRoute(
name: "default",
template: "{controller=Persons}/{action=Index}/{id?}");
pattern: "{controller=Persons}/{action=Index}/{id?}");
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions DataTables.NetStandard.Sample/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"ConnectionStrings": {
"Database": "Server=(localdb)\\mssqllocaldb;Database=DataTables.NetStandard.Sample;Trusted_Connection=True;"
},
"Logging": {
"LogLevel": {
"Default": "Debug",
Expand Down