Skip to content

Commit 6e581e8

Browse files
committed
Ported Autofac sample (#326)
1 parent 99352b3 commit 6e581e8

File tree

7 files changed

+35
-32
lines changed

7 files changed

+35
-32
lines changed

samples/Autofac/Autofac.AssemblyInit.Test/Autofac.AssemblyInit.Test.csproj

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.App" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
13-
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
14-
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0-*" />
12+
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0-*" />
13+
<PackageReference Include="MSTest.TestFramework" Version="2.0.0-*" />
1514
</ItemGroup>
1615

1716
<ItemGroup>

samples/Autofac/Autofac.NoContainerBuilder.Test/Autofac.NoContainerBuilder.Test.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.App" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0-*" />
1312
<PackageReference Include="xunit" Version="2.4.1" />
1413
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
1514
<PrivateAssets>all</PrivateAssets>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
</PropertyGroup>
88

99

1010
<ItemGroup>
1111
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.4.0" />
12-
<PackageReference Include="Microsoft.AspNetCore.App" />
1312
</ItemGroup>
1413

1514
</Project>

samples/Autofac/Autofac.NoContainerBuilder.Web/Startup.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
using Microsoft.AspNetCore.Mvc;
99
using Microsoft.Extensions.Configuration;
1010
using Microsoft.Extensions.DependencyInjection;
11+
using Microsoft.Extensions.Hosting;
1112
using Modules;
1213
using Services;
1314

@@ -28,14 +29,14 @@ public IServiceProvider ConfigureServices(IServiceCollection services)
2829

2930
services.AddSingleton<IDateTimeService>(_ => new DateTimeService());
3031

31-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
32+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
3233

3334
var builder = this.GetContainerBuilder(services);
3435

3536
return new AutofacServiceProvider(builder.Build());
3637
}
3738

38-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
39+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3940
{
4041
if (env.IsDevelopment())
4142
{
@@ -51,16 +52,18 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
5152
app.UseStaticFiles();
5253
app.UseCookiePolicy();
5354

54-
app.UseMvc(routes =>
55+
app.UseRouting();
56+
57+
app.UseEndpoints(endpoints =>
5558
{
56-
routes.MapRoute(
59+
endpoints.MapControllerRoute(
5760
name: "custom",
58-
template: "Index",
61+
pattern: "Index",
5962
defaults: new { controller = "Home", action = "Index" });
6063

61-
routes.MapRoute(
64+
endpoints.MapControllerRoute(
6265
name: "default",
63-
template: "{controller=Home}/{action=Index}/{id?}");
66+
pattern: "{controller=Home}/{action=Index}/{id?}");
6467
});
6568
}
6669

samples/Autofac/Autofac.Test/Autofac.Test.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
66

77
<IsPackable>false</IsPackable>
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="Microsoft.AspNetCore.App" />
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.2.0" />
11+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0-*" />
1312
<PackageReference Include="xunit" Version="2.4.1" />
1413
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1">
1514
<PrivateAssets>all</PrivateAssets>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp2.2</TargetFramework>
4+
<TargetFramework>netcoreapp3.0</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
77
</PropertyGroup>
88

99
<ItemGroup>
1010
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.4.0" />
11-
<PackageReference Include="Microsoft.AspNetCore.App" />
1211
</ItemGroup>
1312

1413
</Project>

samples/Autofac/Autofac.Web/Startup.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using Microsoft.AspNetCore.Mvc;
77
using Microsoft.Extensions.Configuration;
88
using Microsoft.Extensions.DependencyInjection;
9+
using Microsoft.Extensions.Hosting;
910
using Modules;
1011
using Services;
1112

@@ -26,13 +27,13 @@ public void ConfigureServices(IServiceCollection services)
2627

2728
services.AddSingleton<IDateTimeService>(_ => new DateTimeService());
2829

29-
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
30+
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
3031
}
3132

3233
public void ConfigureContainer(ContainerBuilder builder)
3334
=> builder.RegisterModule(new AutofacModule());
3435

35-
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
36+
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
3637
{
3738
if (env.IsDevelopment())
3839
{
@@ -45,19 +46,23 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
4546
}
4647

4748
app.UseHttpsRedirection();
49+
4850
app.UseStaticFiles();
51+
4952
app.UseCookiePolicy();
5053

51-
app.UseMvc(routes =>
54+
app.UseRouting();
55+
56+
app.UseEndpoints(endpoints =>
5257
{
53-
routes.MapRoute(
58+
endpoints.MapControllerRoute(
5459
name: "custom",
55-
template: "Index",
60+
pattern: "Index",
5661
defaults: new { controller = "Home", action = "Index" });
5762

58-
routes.MapRoute(
63+
endpoints.MapControllerRoute(
5964
name: "default",
60-
template: "{controller=Home}/{action=Index}/{id?}");
65+
pattern: "{controller=Home}/{action=Index}/{id?}");
6166
});
6267
}
6368
}

0 commit comments

Comments
 (0)