Skip to content

Get Started

Thang Chung edited this page Oct 30, 2018 · 6 revisions

Up and Running

1. Simple type

  • Open up the netcore-kit.sln
  • Start with the project NetCoreKit.Samples.TodoAPI
  • Then press F5, we should see OpenAPI UI of samples\TodoApi sample
  • Just play around with it.

2. Persistence type

  • Open up the netcore-kit.sln
  • Start with the project NetCoreKit.Samples.TodoAPI

Dockers

  1. SQL Server
> docker run --name sqlserverdb -p 1433:1433 -e ACCEPT_EULA=Y -e MSSQL_SA_PASSWORD=Passw0rd  microsoft/mssql-server-linux:2017-latest
  1. MySQL
> docker run --name mysqldb -p 3306:3306 -e MYSQL_ROOT_PASSWORD=P@ssw0rd -e MYSQL_PASSWORD=P@ssw0rd mysql:8.0.12

Change code and settings

  • Add middleware in samples\TodoApi\Startup.cs as following
services.AddMiniService<TodoDbContext>(
  new[] {typeof(Startup)},
    svc =>
    {
      // svc.AddEfCoreSqlServerDb();
      svc.AddEfCoreMySqlDb();
      svc.AddExternalSystemHealthChecks();
    });
  • Put connection string for each type of database into ConnectionStrings section in the appsettings.json file as below
"mssqldb": "Server=tcp:127.0.0.1,1433;Database=maindb;User Id=cs;Password=P@ssw0rd;"
"mysqldb": "server=127.0.0.1;port=3306;uid=root;pwd=P@ssw0rd;database=maindb"

If you run it on Kubernetes:

  "k8s": {
    "mysqldb": {
      "Host": "TODOLISTDB_SERVICE_HOST",
      "Port": "TODOLISTDB_SERVICE_PORT",
      "Database": "maindb",
      "UserName": "root",
      "Password": "P@ssw0rd",
      "Major": 8,
      "Minor": 0,
      "Build": 12,
      "DbType": 0
    }
  }
  • Then press F5

3. Pub/Sub type

  • Open up the netcore-kit.sln
  • Start with 2 projects NetCoreKit.Samples.TodoAPI and NetCoreKit.Samples.Notifier

Docker

> docker run -d -p 2181:2181 -p 9092:9092 --env ADVERTISED_HOST=127.0.0.1 --env ADVERTISED_PORT=9092 spotify/kafka

Change code and settings

  • Change appsettings.json for NetCoreKit.Samples.TodoAPI and NetCoreKit.Samples.Notifier as following
  "EventBus": {
    "Brokers": "127.0.0.1:9092"
  }
  • Change code for projects
// publisher
services.AddMiniService<TodoListDbContext>(
	svc =>
	{
		  svc.AddKafkaEventBus();
	}
);
// subcriber
services.AddKafkaEventBus();
  • Press F5, then try to create a new project on the OpenAPI UI
  • See the subscriber work on the notifier.

Notes: To generating protobuf contract, please follow the guidance

> cd <to-root-of-project>
> protoc samples\protos\project.proto --csharp_out .\samples\Contracts