You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This tutorial will walk through a basic .NET Core JSON API application that performs CRUD operations on
15
15
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` (
27
27
```
28
28
29
29
### Initialize .NET Core MVC
30
-
Create a new directory for the project with a `project.json` file at the root:
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.
68
31
69
-
Run the command `dotnet restore` in this directory.
32
+
### Update Configuration Files
70
33
71
-
### Add Configuration Files
72
-
73
-
The first building block of our appplication is definig a couple JSON files to hold configuration:
`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.
145
79
```csharp
146
-
usingMicrosoft.AspNetCore.Hosting;
147
-
148
-
namespaceMySqlConnector.Performance
149
-
{
150
-
publicclassProgram
151
-
{
152
-
publicstaticvoidMain(string[] args)
153
-
{
154
-
varhost=newWebHostBuilder()
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
-
usingSystem.Buffers;
167
-
usingMicrosoft.AspNetCore.Builder;
168
-
usingMicrosoft.AspNetCore.Hosting;
169
-
usingMicrosoft.AspNetCore.Mvc.Formatters;
170
-
usingMicrosoft.Extensions.Configuration;
171
-
usingMicrosoft.Extensions.DependencyInjection;
172
-
usingMicrosoft.Extensions.Logging;
173
-
usingNewtonsoft.Json;
174
-
175
-
namespaceMySqlConnector.Performance
176
-
{
177
-
publicclassStartup
178
-
{
179
-
publicStartup(IHostingEnvironmentenv)
180
-
{
181
-
Configuration=AppConfig.Config;
182
-
}
183
-
184
-
publicIConfigurationRootConfiguration { get; }
185
-
186
-
// This method gets called by the runtime. Use this method to add services to the container.
0 commit comments