Skip to content

Commit 4cbcd94

Browse files
authored
Merge pull request #373 from dustinsoftware/update-docs
Update docs to .NET Core 2.0.
2 parents dbc1f97 + 1d835d0 commit 4cbcd94

File tree

3 files changed

+40
-170
lines changed

3 files changed

+40
-170
lines changed

docs/content/overview/installing.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
lastmod: 2016-10-16
2+
lastmod: 2017-10-21
33
date: 2016-10-16
44
menu:
55
main:
@@ -13,18 +13,22 @@ Installing
1313

1414
The recommended way of installing MySqlConnector is through [NuGet](https://www.nuget.org/packages/MySqlConnector/)
1515

16-
**Step 1:** Add MySqlConnector to the dependencies in your `project.json` file:
16+
**Step 1:** Add MySqlConnector to the dependencies in your `csproj` file:
1717

18-
```json
19-
{
20-
"title": "My Application",
21-
"description": "A great application",
22-
"dependencies": {
23-
"MySqlConnector": "0.*",
24-
// other dependencies
25-
},
26-
// other config
27-
}
28-
```
18+
```xml
19+
<Project Sdk="Microsoft.NET.Sdk">
20+
<PropertyGroup>
21+
<AssemblyTitle>My Application</AssemblyTitle>
22+
<Description>A great application</Description>
23+
<OutputType>Exe</OutputType>
24+
<TargetFramework>netcoreapp2.0</TargetFramework>
25+
</PropertyGroup>
2926

30-
**Step 2:** Run the command `dotnet restore`
27+
<ItemGroup>
28+
<PackageReference Include="MySqlConnector" Version="0.28.2" />
29+
</ItemGroup>
30+
31+
</Project>
32+
```
33+
34+
**Step 2:** Run the command `dotnet restore`

docs/content/tutorials/best-practices.md

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
lastmod: 2016-10-16
2+
lastmod: 2017-10-21
33
date: 2016-10-16
44
menu:
55
main:
@@ -158,17 +158,12 @@ concurrent connections you plan to support. For example, if you are creating a
158158
synchronous methods that needs to support serving 500 Requests Per Second, set the minimum thread
159159
pool size to 500.
160160

161-
Example `project.json` configuration:
161+
Example `csproj` configuration:
162162

163-
```json
164-
{
165-
"runtimeOptions": {
166-
"configProperties": {
167-
"System.GC.Server": true,
168-
"System.GC.Concurrent": true,
169-
"System.Threading.ThreadPool.MinThreads": 500
170-
}
171-
},
172-
// other config
173-
}
163+
```xml
164+
<PropertyGroup>
165+
<ServerGarbageCollection>true</ServerGarbageCollection>
166+
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
167+
<ThreadPoolMinThreads>500</ThreadPoolMinThreads>
168+
</PropertyGroup>
174169
```

docs/content/tutorials/net-core-mvc.md

Lines changed: 14 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
lastmod: 2016-10-16
2+
lastmod: 2017-10-21
33
date: 2016-10-16
44
menu:
55
main:
@@ -8,8 +8,8 @@ title: Use with .NET Core MVC
88
weight: 30
99
---
1010

11-
Use with .NET Core MVC
12-
======================
11+
Use with .NET Core MVC 2.0
12+
==========================
1313

1414
This tutorial will walk through a basic .NET Core JSON API application that performs CRUD operations on
1515
blog posts. The code in this tutorial comes is an adaptation of [MySqlConnector.Performance](https://github.com/mysql-net/MySqlConnector/tree/master/tests/MySqlConnector.Performance),
@@ -27,52 +27,11 @@ CREATE TABLE IF NOT EXISTS `BlogPost` (
2727
```
2828

2929
### Initialize .NET Core MVC
30-
Create a new directory for the project with a `project.json` file at the root:
31-
```json
32-
{
33-
"dependencies": {
34-
"Microsoft.AspNetCore.Mvc": "1.0.0",
35-
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
36-
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
37-
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
38-
"Microsoft.Extensions.Configuration.Json": "1.0.0",
39-
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
40-
"Microsoft.Extensions.Logging": "1.0.0",
41-
"Microsoft.Extensions.Logging.Console": "1.0.0",
42-
"Microsoft.Extensions.Logging.Debug": "1.0.0",
43-
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
44-
"MySqlConnector": "0.*"
45-
},
46-
47-
"frameworks": {
48-
"netcoreapp1.0": {
49-
"dependencies": {
50-
"Microsoft.NETCore.App": {
51-
"type": "platform",
52-
"version": "1.0.0"
53-
}
54-
}
55-
}
56-
},
57-
58-
"runtimeOptions": {
59-
"gcServer": true
60-
},
61-
62-
"buildOptions": {
63-
"emitEntryPoint": true,
64-
"preserveCompilationContext": true
65-
}
66-
}
67-
```
30+
Run `dotnet new webapi` at the root to create the initial project, then run `dotnet add package MySqlConnector`. You should have a working project at this point, use `dotnet run` to verify the project builds and runs successfully.
6831

69-
Run the command `dotnet restore` in this directory.
32+
### Update Configuration Files
7033

71-
### Add Configuration Files
72-
73-
The first building block of our appplication is definig a couple JSON files to hold configuration:
74-
75-
`appsettings.json` holds .NET Core logging levels:
34+
`appsettings.json` holds .NET Core logging levels and the ADO.NET Connection String:
7635
```json
7736
{
7837
"Logging": {
@@ -82,33 +41,9 @@ The first building block of our appplication is definig a couple JSON files to h
8241
"System": "Error",
8342
"Microsoft": "Error"
8443
}
85-
}
86-
}
87-
```
88-
89-
`config.json` holds the ADO.NET Connection String:
90-
```json
91-
{
92-
"Data": {
93-
"ConnectionString": "server=127.0.0.1;user id=mysqltest;password=test;port=3306;database=blog;"
94-
}
95-
}
96-
```
97-
98-
`AppConfig.cs` is a static class that builds a Configuration object from these files:
99-
```csharp
100-
using System.IO;
101-
using Microsoft.Extensions.Configuration;
102-
103-
namespace MySqlConnector.Performance
104-
{
105-
public static class AppConfig
106-
{
107-
public static IConfigurationRoot Config = new ConfigurationBuilder()
108-
.SetBasePath(Directory.GetCurrentDirectory())
109-
.AddJsonFile("appsettings.json")
110-
.AddJsonFile("config.json")
111-
.Build();
44+
},
45+
"ConnectionStrings": {
46+
"DefaultConnection": "server=127.0.0.1;user id=mysqltest;password=test;port=3306;database=blog;",
11247
}
11348
}
11449
```
@@ -123,12 +58,11 @@ namespace MySqlConnector.Performance
12358
{
12459
public class AppDb : IDisposable
12560
{
126-
12761
public MySqlConnection Connection;
12862

129-
public AppDb()
63+
public AppDb(string connectionString)
13064
{
131-
Connection = new MySqlConnection(AppConfig.Config["Data:ConnectionString"]);
65+
Connection = new MySqlConnection(connectionString);
13266
}
13367

13468
public void Dispose()
@@ -139,74 +73,11 @@ namespace MySqlConnector.Performance
13973
}
14074
```
14175

142-
### .NET Core Program.cs and Startup.cs Files
76+
### .NET Core Startup
14377

144-
`Program.cs` contains the application entry point:
78+
`Startup.cs` contains runtime configuration and framework services. Add this call to `ConfigureServices` to make an instance of `AppDb` available to controller methods.
14579
```csharp
146-
using Microsoft.AspNetCore.Hosting;
147-
148-
namespace MySqlConnector.Performance
149-
{
150-
public class Program
151-
{
152-
public static void Main(string[] args)
153-
{
154-
var host = new WebHostBuilder()
155-
.UseKestrel()
156-
.UseStartup<Startup>()
157-
.Build();
158-
host.Run();
159-
}
160-
}
161-
}
162-
```
163-
164-
`Startup.cs` contains runtime configuration and framework services:
165-
```csharp
166-
using System.Buffers;
167-
using Microsoft.AspNetCore.Builder;
168-
using Microsoft.AspNetCore.Hosting;
169-
using Microsoft.AspNetCore.Mvc.Formatters;
170-
using Microsoft.Extensions.Configuration;
171-
using Microsoft.Extensions.DependencyInjection;
172-
using Microsoft.Extensions.Logging;
173-
using Newtonsoft.Json;
174-
175-
namespace MySqlConnector.Performance
176-
{
177-
public class Startup
178-
{
179-
public Startup(IHostingEnvironment env)
180-
{
181-
Configuration = AppConfig.Config;
182-
}
183-
184-
public IConfigurationRoot Configuration { get; }
185-
186-
// This method gets called by the runtime. Use this method to add services to the container.
187-
public void ConfigureServices(IServiceCollection services)
188-
{
189-
// Add framework services.
190-
services.AddMvc(options =>
191-
{
192-
options.OutputFormatters.Clear();
193-
options.OutputFormatters.Add(new JsonOutputFormatter(new JsonSerializerSettings()
194-
{
195-
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
196-
}, ArrayPool<char>.Shared));
197-
});
198-
}
199-
200-
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
201-
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
202-
{
203-
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
204-
loggerFactory.AddDebug();
205-
206-
app.UseMvc();
207-
}
208-
}
209-
}
80+
services.AddTransient<AppDb>(_ => new AppDb(Configuration["ConnectionStrings:DefaultConnection"]));
21081
```
21182

21283
Now our app is configured and we can focus on writing the core functionality!

0 commit comments

Comments
 (0)