Skip to content

Commit a6fa0bf

Browse files
committed
migrate to core 2.0
1 parent 35e92b2 commit a6fa0bf

File tree

21 files changed

+90
-182
lines changed

21 files changed

+90
-182
lines changed

README.MD

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Service Discovery Patterns with ASP.NET Core
22

3-
This repo contains a samples of implementing Service Discovery patterns with ASP.NET Core using tools like [Consul](https://www.consul.io) and [RabbitMQ](http://www.rabbitmq.com/)
3+
This repo contains a samples of implementing Service Discovery patterns with ASP.NET Core using tools like [Consul](https://www.consul.io) and [RabbitMQ](http://www.rabbitmq.com/).
4+
5+
The master branch is currently using .NET Core 2.0 and ASP.NET Core 2.0. If you want to see the ASP.NET Core 1.1 version of the sample see the [aspnetcore1.1 tag](cecilphillip/aspnet-servicediscovery-patterns/tree/aspnetcore1.1)
46

57

68
### Patterns Covered

health_checks/src/SchoolAPI/Program.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.IO;
33
using System.Net;
44
using System.Net.Sockets;
5+
using Microsoft.AspNetCore;
56
using Microsoft.AspNetCore.Hosting;
67
using Microsoft.Extensions.Configuration;
78
using Microsoft.Extensions.Logging;
@@ -12,18 +13,10 @@ public class Program
1213
{
1314
public static void Main(string[] args)
1415
{
15-
var config = new ConfigurationBuilder()
16-
.AddCommandLine(args)
17-
.Build();
18-
1916
var freePort = FreeTcpPort();
2017

21-
var host = new WebHostBuilder()
22-
.UseConfiguration(config)
18+
var host = WebHost.CreateDefaultBuilder(args)
2319
.UseUrls($"http://localhost:{freePort}")
24-
.UseKestrel()
25-
.UseContentRoot(Directory.GetCurrentDirectory())
26-
.UseIISIntegration()
2720
.UseStartup<Startup>()
2821
.Build();
2922

+6-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
55
<PreserveCompilationContext>true</PreserveCompilationContext>
66
<AssemblyName>SchoolAPI</AssemblyName>
77
<OutputType>Exe</OutputType>
88
<PackageId>SchoolAPI</PackageId>
9-
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
10-
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
9+
<AssetTargetFallback>$(AssetTargetFallback);dotnet5.6;portable-net45+win8</AssetTargetFallback>
1110
</PropertyGroup>
1211

1312
<ItemGroup>
@@ -17,18 +16,9 @@
1716
</ItemGroup>
1817

1918
<ItemGroup>
20-
<PackageReference Include="Consul" Version="0.7.2.1" />
21-
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.1.0" />
22-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
23-
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="1.1.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
25-
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
26-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
27-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.0" />
28-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
29-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
30-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.0" />
31-
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0-rc3" />
32-
<PackageReference Include="Bogus" Version="11.0.2" />
19+
<PackageReference Include="Consul" Version="0.7.2.3" />
20+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
21+
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0"/>
22+
<PackageReference Include="Bogus" Version="15.0.6"/>
3323
</ItemGroup>
3424
</Project>

health_checks/src/SchoolAPI/Startup.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ namespace SchoolAPI
1414
{
1515
public class Startup
1616
{
17-
public Startup(IHostingEnvironment env)
17+
public Startup(IConfiguration config)
1818
{
19-
var builder = new ConfigurationBuilder()
20-
.SetBasePath(env.ContentRootPath)
21-
.AddJsonFile("appsettings.json");
22-
23-
Configuration = builder.Build();
19+
Configuration = config;
2420
}
2521

26-
public IConfigurationRoot Configuration { get; set; }
22+
public IConfiguration Configuration { get; set; }
2723

2824
public void ConfigureServices(IServiceCollection services)
2925
{
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp1.1</TargetFramework>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
44
<AssemblyName>SchoolClient</AssemblyName>
55
<OutputType>Exe</OutputType>
66
<PackageId>SchoolClient</PackageId>
7-
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
8-
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
7+
<AssetTargetFallback>$(AssetTargetFallback);dotnet5.6;portable-net45+win8</AssetTargetFallback>
98
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
109
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1110
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
@@ -16,13 +15,11 @@
1615
</Content>
1716
</ItemGroup>
1817
<ItemGroup>
19-
<PackageReference Include="Consul" Version="0.7.2.1" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="1.1.0" />
21-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
22-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
23-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
24-
<PackageReference Include="Polly" Version="5.0.6" />
25-
<PackageReference Include="System.Net.Http" Version="4.3.1" />
18+
<PackageReference Include="Consul" Version="0.7.2.3" />
19+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
21+
<PackageReference Include="Polly" Version="5.3.1" />
22+
<PackageReference Include="System.Net.Http" Version="4.3.2" />
2623
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
2724
</ItemGroup>
2825
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp1.1</TargetFramework>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
44
<AssemblyName>SchoolClient</AssemblyName>
55
<OutputType>Exe</OutputType>
66
<PackageId>SchoolClient</PackageId>
7-
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
87
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
98
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
109
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
@@ -15,11 +14,9 @@
1514
</Content>
1615
</ItemGroup>
1716
<ItemGroup>
18-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
19-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
20-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
21-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="1.1.0" />
22-
<PackageReference Include="System.ComponentModel.Annotations" Version="4.3.0" />
23-
<PackageReference Include="RabbitMQ.Client" Version="5.0.0-pre2" />
17+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
18+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
19+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.0" />
20+
<PackageReference Include="RabbitMQ.Client" Version="5.0.1" />
2421
</ItemGroup>
2522
</Project>

load_balancing/src/SchoolService/Program.cs

-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ private static void DisplayRabbitSettings(QueueConfig config)
3737
Console.WriteLine("*********************");
3838
Console.WriteLine("Host: {0}", config.HostName);
3939
Console.WriteLine("Username: {0}", config.UserName);
40-
Console.WriteLine("Password: {0}", config.Password);
4140
Console.WriteLine("QueueName: {0}", config.QueueName);
4241
Console.WriteLine("*********************");
4342
Console.WriteLine();

load_balancing/src/SchoolService/QueueProcessor.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public QueueProcessor(QueueConfig config)
2727
Password = config.Password
2828
};
2929

30-
_connection = _connectionFactory.CreateConnection();
30+
_connection = _connectionFactory.CreateConnection("QueueProcessor Connection");
3131
_model = _connection.CreateModel();
3232
_model.BasicQos(0, 1, false);
3333

@@ -78,6 +78,9 @@ public void Start()
7878

7979
Console.WriteLine("Press [enter] to exit.");
8080
Console.ReadLine();
81+
82+
_model.Dispose();
83+
_connection.Dispose();
8184
}
8285
}
8386
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp1.1</TargetFramework>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
44
<AssemblyName>SchoolService</AssemblyName>
55
<OutputType>Exe</OutputType>
66
<PackageId>SchoolService</PackageId>
7-
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
87
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
98
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
109
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
1110
</PropertyGroup>
1211
<ItemGroup>
13-
<PackageReference Include="Bogus" Version="11.0.2" />
14-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
15-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.2" />
16-
<PackageReference Include="RabbitMQ.Client" Version="5.0.0-pre2" />
17-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
18-
<PackageReference Include="System.ComponentModel.Annotations" Version="4.3.0" />
12+
<PackageReference Include="Bogus" Version="15.0.6" />
13+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
14+
<PackageReference Include="RabbitMQ.Client" Version="5.0.1" />
15+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
16+
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.0" />
1917
</ItemGroup>
2018
</Project>

local_registry/src/SchoolAPI/Program.cs

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using System.IO;
3+
using Microsoft.AspNetCore;
34
using Microsoft.AspNetCore.Hosting;
45
using Microsoft.Extensions.Configuration;
56
using Microsoft.Extensions.Logging;
@@ -10,21 +11,14 @@ public class Program
1011
{
1112
public static void Main(string[] args)
1213
{
13-
var config = new ConfigurationBuilder()
14-
.AddCommandLine(args)
15-
.Build();
16-
17-
var host = new WebHostBuilder()
18-
.UseConfiguration(config)
19-
.UseKestrel()
20-
.UseContentRoot(Directory.GetCurrentDirectory())
21-
.UseIISIntegration()
14+
var host = WebHost.CreateDefaultBuilder(args)
2215
.UseStartup<Startup>()
2316
.Build();
2417

2518
var loggingFactory = host.Services.GetService(typeof(ILoggerFactory)) as ILoggerFactory;
2619
var logger = loggingFactory.CreateLogger(nameof(Program));
2720
logger.LogInformation($"Process ID: {Process.GetCurrentProcess().Id}");
21+
2822
host.Run();
2923
}
3024
}
+5-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1</TargetFramework>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
55
<PreserveCompilationContext>true</PreserveCompilationContext>
66
<AssemblyName>SchoolAPI</AssemblyName>
77
<OutputType>Exe</OutputType>
88
<PackageId>SchoolAPI</PackageId>
9-
<PackageTargetFallback >$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
10-
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
9+
<AssetTargetFallback >$(AssetTargetFallback);dotnet5.6;portable-net45+win8</AssetTargetFallback>
1110
</PropertyGroup>
1211

1312
<ItemGroup>
@@ -17,16 +16,8 @@
1716
</ItemGroup>
1817

1918
<ItemGroup>
20-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0" />
21-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1" />
22-
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.1.0" />
23-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
24-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0" />
25-
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0" />
26-
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="1.1.0" />
27-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
28-
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0-rc3" />
29-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.0" />
30-
<PackageReference Include="Bogus" Version="11.0.2" />
19+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
20+
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0"/>
21+
<PackageReference Include="Bogus" Version="15.0.6"/>
3122
</ItemGroup>
3223
</Project>

local_registry/src/SchoolAPI/Startup.cs

+3-7
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,12 @@ namespace SchoolAPI
1212
{
1313
public class Startup
1414
{
15-
public Startup(IHostingEnvironment env)
15+
public Startup(IConfiguration config)
1616
{
17-
var builder = new ConfigurationBuilder()
18-
.SetBasePath(env.ContentRootPath)
19-
.AddJsonFile("appsettings.json");
20-
21-
Configuration = builder.Build();
17+
Configuration = config;
2218
}
2319

24-
public IConfigurationRoot Configuration { get; set; }
20+
public IConfiguration Configuration { get; set; }
2521

2622
public void ConfigureServices(IServiceCollection services)
2723
{
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netcoreapp1.0</TargetFramework>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
44
<AssemblyName>SchoolClient</AssemblyName>
55
<OutputType>Exe</OutputType>
66
<PackageId>SchoolClient</PackageId>
7-
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
8-
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
7+
<AssetTargetFallback>$(AssetTargetFallback);dotnet5.6;portable-net45+win8</AssetTargetFallback>
98
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
109
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
1110
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
@@ -16,12 +15,11 @@
1615
</Content>
1716
</ItemGroup>
1817
<ItemGroup>
19-
<PackageReference Include="Microsoft.Extensions.Logging" Version="1.1.2" />
20-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0" />
21-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0" />
22-
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="1.1.0" />
23-
<PackageReference Include="System.Net.Http" Version="4.3.1" />
24-
<PackageReference Include="Polly" Version="5.0.6" />
18+
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="2.0.0" />
19+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
20+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
21+
<PackageReference Include="System.Net.Http" Version="4.3.2" />
22+
<PackageReference Include="Polly" Version="5.3.1" />
2523
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.3" />
2624
</ItemGroup>
2725
</Project>

point_to_point/src/SchoolAPI/Program.cs

+2-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Diagnostics;
22
using System.IO;
3+
using Microsoft.AspNetCore;
34
using Microsoft.AspNetCore.Hosting;
45
using Microsoft.Extensions.Configuration;
56
using Microsoft.Extensions.Logging;
@@ -10,15 +11,7 @@ public class Program
1011
{
1112
public static void Main(string[] args)
1213
{
13-
var config = new ConfigurationBuilder()
14-
.AddCommandLine(args)
15-
.Build();
16-
17-
var host = new WebHostBuilder()
18-
.UseConfiguration(config)
19-
.UseKestrel()
20-
.UseContentRoot(Directory.GetCurrentDirectory())
21-
.UseIISIntegration()
14+
var host = WebHost.CreateDefaultBuilder(args)
2215
.UseStartup<Startup>()
2316
.Build();
2417

+5-16
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
21
<Project Sdk="Microsoft.NET.Sdk.Web">
32
<PropertyGroup>
4-
<TargetFramework>netcoreapp1.1</TargetFramework>
3+
<TargetFramework>netcoreapp2.0</TargetFramework>
54
<PreserveCompilationContext>true</PreserveCompilationContext>
65
<AssemblyName>SchoolAPI</AssemblyName>
76
<OutputType>Exe</OutputType>
87
<PackageId>SchoolAPI</PackageId>
9-
<PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
10-
<RuntimeFrameworkVersion>1.1.0</RuntimeFrameworkVersion>
8+
<AssetTargetFallback>$(AssetTargetFallback);dotnet5.6;portable-net45+win8</AssetTargetFallback>
119
</PropertyGroup>
1210
<ItemGroup>
1311
<Content Update="wwwroot;appsettings.json;web.config">
1412
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
1513
</Content>
1614
</ItemGroup>
1715
<ItemGroup>
18-
<PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.1.0"/>
19-
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.1"/>
20-
<PackageReference Include="Microsoft.AspNetCore.Cors" Version="1.1.0"/>
21-
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="1.1.0"/>
22-
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.1.0"/>
23-
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.1.0"/>
24-
<PackageReference Include="Microsoft.AspNetCore.Http.Extensions" Version="1.1.0"/>
25-
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.0"/>
26-
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0-rc3"/>
27-
<PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="1.1.0"/>
28-
<PackageReference Include="Bogus" Version="11.0.2"/>
29-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="1.1.2"/>
16+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
17+
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0"/>
18+
<PackageReference Include="Bogus" Version="15.0.6"/>
3019
</ItemGroup>
3120
</Project>

0 commit comments

Comments
 (0)