Skip to content

Commit

Permalink
Updating WebApi template to use asp net core 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
thepirat000 committed Aug 1, 2020
1 parent e331c53 commit 6607a05
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
2 changes: 1 addition & 1 deletion templates/WebApi/Audit.WebApi.Template.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>Audit.WebApi.Template</id>
<version>0.0.7</version>
<version>1.0.0</version>
<description>Audited Web API</description>
<authors>Federico Colombo</authors>
<packageTypes>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
<AssemblyName>Audit.WebApi.Template</AssemblyName>
<AssemblyTitle>Audit.WebApi.Template</AssemblyTitle>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFramework>netcoreapp2.2</TargetFramework>
<TargetFramework>netcoreapp3.0</TargetFramework>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<!--#if (EnableEntityFramework)-->
<DefineConstants>DEBUG;EnableEntityFramework;NETCOREAPP;NETCOREAPP2_2</DefineConstants>
<DefineConstants>DEBUG;EnableEntityFramework;NETCOREAPP;NETCOREAPP3_0</DefineConstants>
<!--#endif-->
<!--#if (Swagger)-->
<DefineConstants>DEBUG;Swagger;NETCOREAPP;NETCOREAPP2_2</DefineConstants>
<DefineConstants>DEBUG;Swagger;NETCOREAPP;NETCOREAPP3_0</DefineConstants>
<!--#endif-->
<NoWarn>1701;1702;CS1591</NoWarn>
</PropertyGroup>
Expand All @@ -25,16 +25,16 @@

<ItemGroup>
<PackageReference Include="Audit.WebApi.Core" Version="*" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<!--#if (EnableEntityFramework)-->
<PackageReference Include="Audit.EntityFramework.Core" Version="*" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.2.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<!--#endif-->

<!--#if (Swagger)-->
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="5.5.1" />
<!--#endif-->
</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ namespace Audit.WebApi.Template.Controllers
[ApiController]
public class TestController : ControllerBase
{
private readonly IHostingEnvironment _hostingEnvironment;
private readonly IWebHostEnvironment _hostingEnvironment;

public TestController(IServiceProvider serviceProvider)
{
_hostingEnvironment = serviceProvider.GetRequiredService<IHostingEnvironment>();
_hostingEnvironment = serviceProvider.GetRequiredService<IWebHostEnvironment>();
}
[HttpGet()]
public IActionResult Test()
Expand Down
19 changes: 11 additions & 8 deletions templates/WebApi/content/Audit.WebApi.Template/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http.Internal;
using Microsoft.Extensions.Hosting;
#if (EnableEntityFramework)
using Microsoft.EntityFrameworkCore;
using Audit.WebApi.Template.Providers.Database;
#endif
#if (Swagger)
using System.IO;
using Swashbuckle.AspNetCore.Swagger;
using Microsoft.OpenApi.Models;
#endif

namespace Audit.WebApi.Template
Expand All @@ -22,7 +23,7 @@ public class Startup
{
public IConfiguration Configuration { get; }

public Startup(IConfiguration configuration, IHostingEnvironment env)
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
Expand All @@ -40,7 +41,7 @@ public void ConfigureServices(IServiceCollection services)
#if (Swagger)
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info
c.SwaggerDoc("v1", new OpenApiInfo
{
Version = "v1",
Title = "Audit.WebApi.Template API",
Expand All @@ -50,17 +51,19 @@ public void ConfigureServices(IServiceCollection services)
var xmlPath = Path.Combine(basePath, "Audit.WebApi.Template.xml");
c.IncludeXmlComments(xmlPath);
c.DescribeAllParametersInCamelCase();
c.DescribeStringEnumsInCamelCase();
});
#endif
services
.ConfigureAudit()
.AddMvc(_ => _.AddAudit())
.SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
.AddMvc(options =>
{
options.AddAudit();
options.EnableEndpointRouting = false;
});
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHttpContextAccessor contextAccessor)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IHttpContextAccessor contextAccessor)
{
if (env.IsDevelopment())
{
Expand All @@ -75,7 +78,7 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IHttpCon
});
#endif
app.Use(async (context, next) => {
context.Request.EnableRewind();
context.Request.EnableBuffering();
await next();
});

Expand Down

0 comments on commit 6607a05

Please sign in to comment.