This commit is contained in:
bart-vmware 2022-12-13 13:37:54 +01:00
Родитель 703e2eb719
Коммит 34cb012b52
4 изменённых файлов: 31 добавлений и 14 удалений

Просмотреть файл

@ -2,31 +2,46 @@
[![Build Status](https://dev.azure.com/SteeltoeOSS/Steeltoe/_apis/build/status/Samples/SteeltoeOSS.Samples%20%5BConnectors_MySqlEFCore%5D?branchName=main)](https://dev.azure.com/SteeltoeOSS/Steeltoe/_build/latest?definitionId=18&branchName=main)
ASP.NET Core sample app illustrating how to use the EntityFramework Core together with [Steeltoe MySql Connector](https://docs.steeltoe.io/api/v3/connectors/mysql.html) for connecting to a MySql service on CloudFoundry. There is also an additional sample which illustrates how to use a `MySqlConnection` to issue commands to the bound database.
ASP.NET Core sample app illustrating how to use Entity Framework Core together with [Steeltoe MySql Connector](https://docs.steeltoe.io/api/v3/connectors/mysql.html) for connecting to a MySql service on CloudFoundry. There is also an additional sample which illustrates how to use a `MySqlConnection` to issue commands to the bound database.
## Pre-requisites - CloudFoundry
## General Pre-requisites
1. Installed .NET Core SDK
## Running Locally
1. Installed MySQL Server
1. Created MySQL database and user with appropriate access level
1. Set [ASPNETCORE_ENVIRONMENT=Development] (<https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments>)
1. Added your connection string to appsettings.development.json under MySql:Client:ConnectionString
## Running on CloudFoundry
1. Installed Pivotal CloudFoundry
1. (Optional) installed Windows support
1. Installed MySql marketplace service
1. Installed .NET Core SDK
1. Installed MySql CloudFoundry service
## Create MySql Service Instance on CloudFoundry
You must first create an instance of the MySql service in a org/space.
You must first create an instance of the MySql service in an org/space.
1. `cf target -o myorg -s development`
1. `cf create-service p.mysql 100-mb myMySqlService`
1. `cf create-service p.mysql db-small myMySqlService`
## Publish App & Push to CloudFoundry
1. `cf target -o myorg -s development`
1. `cd samples/Connectors/src/MySqlEFCore`
1. `dotnet restore --configfile nuget.config`
1. Publish app to a local directory, specifying the framework and runtime (select ONE of these commands):
* `dotnet publish -f netcoreapp3.1 -r linux-x64`
1. Push the app using the appropriate manifest (select ONE of these commands):
* `cf push -f manifest.yml -p bin/Debug/netcoreapp3.1/linux-x64/publish`
1. Push the app
- When using Windows containers:
- Publish app to a local directory, specifying the runtime:
* `dotnet publish -r win-x64`
- Push the app using the appropriate manifest:
* `cf push -f manifest-windows.yml -p bin/Debug/net6.0/win-x64/publish`
- Otherwise:
- Push the app using the appropriate manifest:
* `cf push -f manifest.yml`
> Note: The provided manifest will create an app named `mysqlefcore-connector` and attempt to bind the app to MySql service `myMySqlService`.
@ -47,8 +62,8 @@ On a Windows cell, you should see something like this during startup:
This sample will be available at <http://mysqlefcore-connector.[your-cf-apps-domain]/>.
Upon startup the app should create a table named `EFCoreTestData` and insert two rows. To display those rows, click on the `MySql Data` link in the menu.
Upon startup, the app inserts a couple rows into the bound MySql database. To display those rows, click on the `MySql Data` link in the menu.
---
### See the Official [Steeltoe Service Connectors Documentation](https://steeltoe.io/docs/steeltoe-service-connectors) for a more in-depth walkthrough of the samples and more detailed information
### See the Official [Steeltoe Service Connectors Documentation](https://steeltoe.io/docs/steeltoe-service-connectors) for a more in-depth walkthrough of the samples and more detailed information.

Просмотреть файл

@ -10,11 +10,11 @@
},
"MySql": {
"Client": {
"ConnectionString": "Server=localhost;Database=steeltoe2;Uid=root;Pwd=steeltoe;"
"ConnectionString": "Server=localhost;Database=steeltoe;Uid=steeltoe;Pwd=steeltoe"
// setting the connection string this way works fine with a single database
}
}/*,
"multipleMySqlDatabases": false,
"multipleMySqlDatabases": true,
// to add multiple databases of the same type, use this structure
"services": {
"local-mysql": [

Просмотреть файл

@ -1,6 +1,7 @@
---
applications:
- name: mysqlefcore-connector
random-route: true
memory: 256M
stack: windows
buildpacks:

Просмотреть файл

@ -1,6 +1,7 @@
---
applications:
- name: mysqlefcore-connector
random-route: true
buildpacks:
- dotnet_core_buildpack
memory: 256M