Skip to content

Commit d0ff2c3

Browse files
committed
Upgrade to .NET 6.0
1 parent 5eee3e9 commit d0ff2c3

File tree

11 files changed

+111
-157
lines changed

11 files changed

+111
-157
lines changed

MyApp.ServiceInterface/MyApp.ServiceInterface.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

MyApp.ServiceModel/MyApp.ServiceModel.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
</PropertyGroup>
66

77
<ItemGroup>

MyApp.Tests/IntegrationTest.cs

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,42 +4,41 @@
44
using MyApp.ServiceInterface;
55
using MyApp.ServiceModel;
66

7-
namespace MyApp.Tests
7+
namespace MyApp.Tests;
8+
9+
public class IntegrationTest
810
{
9-
public class IntegrationTest
11+
const string BaseUri = "http://localhost:2000/";
12+
private readonly ServiceStackHost appHost;
13+
14+
class AppHost : AppSelfHostBase
1015
{
11-
const string BaseUri = "http://localhost:2000/";
12-
private readonly ServiceStackHost appHost;
16+
public AppHost() : base(nameof(IntegrationTest), typeof(MyServices).Assembly) { }
1317

14-
class AppHost : AppSelfHostBase
18+
public override void Configure(Container container)
1519
{
16-
public AppHost() : base(nameof(IntegrationTest), typeof(MyServices).Assembly) { }
17-
18-
public override void Configure(Container container)
19-
{
20-
}
2120
}
21+
}
2222

23-
public IntegrationTest()
24-
{
25-
appHost = new AppHost()
26-
.Init()
27-
.Start(BaseUri);
28-
}
23+
public IntegrationTest()
24+
{
25+
appHost = new AppHost()
26+
.Init()
27+
.Start(BaseUri);
28+
}
2929

30-
[OneTimeTearDown]
31-
public void OneTimeTearDown() => appHost.Dispose();
30+
[OneTimeTearDown]
31+
public void OneTimeTearDown() => appHost.Dispose();
3232

33-
public IServiceClient CreateClient() => new JsonServiceClient(BaseUri);
33+
public IServiceClient CreateClient() => new JsonServiceClient(BaseUri);
3434

35-
[Test]
36-
public void Can_call_Hello_Service()
37-
{
38-
var client = CreateClient();
35+
[Test]
36+
public void Can_call_Hello_Service()
37+
{
38+
var client = CreateClient();
3939

40-
var response = client.Get(new Hello { Name = "World" });
40+
var response = client.Get(new Hello { Name = "World" });
4141

42-
Assert.That(response.Result, Is.EqualTo("Hello, World!"));
43-
}
42+
Assert.That(response.Result, Is.EqualTo("Hello, World!"));
4443
}
4544
}

MyApp.Tests/MyApp.Tests.csproj

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

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<DebugType>portable</DebugType>
66
<OutputType>Library</OutputType>
77
</PropertyGroup>
@@ -10,9 +10,9 @@
1010
<ProjectReference Include="..\MyApp.ServiceInterface\MyApp.ServiceInterface.csproj" />
1111
<ProjectReference Include="..\MyApp.ServiceModel\MyApp.ServiceModel.csproj" />
1212

13-
<PackageReference Include="NUnit" Version="3.12.*" />
14-
<PackageReference Include="NUnit3TestAdapter" Version="3.17.*" />
15-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.*" />
13+
<PackageReference Include="NUnit" Version="3.13.*" />
14+
<PackageReference Include="NUnit3TestAdapter" Version="4.1.*" />
15+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.*" />
1616
<PackageReference Include="ServiceStack" Version="5.*" />
1717
<PackageReference Include="ServiceStack.Kestrel" Version="5.*" />
1818
</ItemGroup>

MyApp.Tests/UnitTest.cs

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,28 @@
44
using MyApp.ServiceInterface;
55
using MyApp.ServiceModel;
66

7-
namespace MyApp.Tests
7+
namespace MyApp.Tests;
8+
9+
public class UnitTest
810
{
9-
public class UnitTest
10-
{
11-
private readonly ServiceStackHost appHost;
11+
private readonly ServiceStackHost appHost;
1212

13-
public UnitTest()
14-
{
15-
appHost = new BasicAppHost().Init();
16-
appHost.Container.AddTransient<MyServices>();
17-
}
13+
public UnitTest()
14+
{
15+
appHost = new BasicAppHost().Init();
16+
appHost.Container.AddTransient<MyServices>();
17+
}
1818

19-
[OneTimeTearDown]
20-
public void OneTimeTearDown() => appHost.Dispose();
19+
[OneTimeTearDown]
20+
public void OneTimeTearDown() => appHost.Dispose();
2121

22-
[Test]
23-
public void Can_call_MyServices()
24-
{
25-
var service = appHost.Container.Resolve<MyServices>();
22+
[Test]
23+
public void Can_call_MyServices()
24+
{
25+
var service = appHost.Container.Resolve<MyServices>();
2626

27-
var response = (HelloResponse)service.Any(new Hello { Name = "World" });
27+
var response = (HelloResponse)service.Any(new Hello { Name = "World" });
2828

29-
Assert.That(response.Result, Is.EqualTo("Hello, World!"));
30-
}
29+
Assert.That(response.Result, Is.EqualTo("Hello, World!"));
3130
}
32-
}
31+
}

MyApp/Configure.AppHost.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Funq;
2+
using ServiceStack;
3+
using MyApp.ServiceInterface;
4+
5+
[assembly: HostingStartup(typeof(MyApp.AppHost))]
6+
7+
namespace MyApp;
8+
9+
public class AppHost : AppHostBase, IHostingStartup
10+
{
11+
public void Configure(IWebHostBuilder builder) => builder
12+
.ConfigureServices(services => {
13+
// Configure ASP.NET Core IOC Dependencies
14+
#if DEBUG
15+
services.AddMvc(options => options.EnableEndpointRouting = false).AddRazorRuntimeCompilation();
16+
#else
17+
services.AddMvc(options => options.EnableEndpointRouting = false);
18+
#endif
19+
})
20+
.Configure(app => {
21+
app.UseStaticFiles();
22+
23+
// Configure ASP.NET Core App
24+
if (!HasInit)
25+
app.UseServiceStack(new AppHost());
26+
27+
app.UseMvc(routes =>
28+
{
29+
routes.MapRoute(
30+
name: "default",
31+
template: "{controller=Home}/{action=Index}/{id?}");
32+
});
33+
});
34+
35+
public AppHost() : base("MyApp", typeof(MyServices).Assembly) {}
36+
37+
public override void Configure(Container container)
38+
{
39+
SetConfig(new HostConfig {
40+
});
41+
}
42+
}

MyApp/Models/ErrorViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace MyApp.Models
44
{
55
public class ErrorViewModel
66
{
7-
public string RequestId { get; set; }
7+
public string? RequestId { get; set; }
88

99
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
1010
}

MyApp/MyApp.csproj

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
57
</PropertyGroup>
68

79
<ItemGroup>

MyApp/Program.cs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,18 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
7-
using Microsoft.AspNetCore.Builder;
8-
using Microsoft.AspNetCore.Hosting;
9-
using Microsoft.Extensions.Configuration;
10-
using Microsoft.Extensions.DependencyInjection;
11-
using Microsoft.Extensions.Hosting;
12-
using Microsoft.Extensions.Logging;
13-
using ServiceStack;
1+
var builder = WebApplication.CreateBuilder(args);
142

15-
namespace MyApp
16-
{
17-
public class Program
18-
{
19-
public static void Main(string[] args)
20-
{
21-
CreateWebHostBuilder(args).Build().Run();
22-
}
3+
var app = builder.Build();
234

24-
public static IHostBuilder CreateWebHostBuilder(string[] args) =>
25-
Host.CreateDefaultBuilder(args)
26-
.ConfigureWebHostDefaults(webBuilder =>
27-
{
28-
webBuilder.UseModularStartup<Startup,StartupActivator>();
29-
});
30-
}
5+
// Configure the HTTP request pipeline.
6+
if (!app.Environment.IsDevelopment())
7+
{
8+
app.UseExceptionHandler("/Error");
9+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
10+
app.UseHsts();
11+
app.UseHttpsRedirection();
12+
}
13+
else
14+
{
15+
app.UseDeveloperExceptionPage();
16+
}
3117

32-
public class StartupActivator : ModularStartupActivator
33-
{
34-
public StartupActivator(IConfiguration configuration) : base(configuration) { }
35-
}
36-
}
18+
app.Run();

MyApp/Startup.cs

Lines changed: 0 additions & 70 deletions
This file was deleted.

0 commit comments

Comments
 (0)