Chapter 5. Creating sample applications with .NET 9.0
5.1. Creating the MVC sample application Copy linkLink copied to clipboard!
s2i-dotnetcore-ex is the default Model, View, Controller (MVC) template application for .NET.
This application is used as the example application by the .NET S2I image and can be created directly from the OpenShift UI using the Try Example link.
The application can also be created with the OpenShift client binary (oc).
Procedure
To create the sample application using oc:
Add the .NET application:
oc new-app dotnet:9.0-ubi8~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnet-9.0 --context-dir=app
$ oc new-app dotnet:9.0-ubi8~https://github.com/redhat-developer/s2i-dotnetcore-ex#dotnet-9.0 --context-dir=appCopy to Clipboard Copied! Toggle word wrap Toggle overflow Make the application accessible externally:
oc expose service s2i-dotnetcore-ex
$ oc expose service s2i-dotnetcore-exCopy to Clipboard Copied! Toggle word wrap Toggle overflow Obtain the sharable URL:
oc get route s2i-dotnetcore-ex
$ oc get route s2i-dotnetcore-exCopy to Clipboard Copied! Toggle word wrap Toggle overflow
5.2. Creating the CRUD sample application Copy linkLink copied to clipboard!
s2i-dotnetcore-persistent-ex is a simple Create, Read, Update, Delete (CRUD) .NET web application that stores data in a PostgreSQL database.
Procedure
To create the sample application using oc:
Add the database:
oc new-app postgresql-ephemeral
$ oc new-app postgresql-ephemeralCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add the .NET application:
oc new-app dotnet:9.0-ubi8~https://github.com/redhat-developer/s2i-dotnetcore-persistent-ex#dotnet-9.0 --context-dir app
$ oc new-app dotnet:9.0-ubi8~https://github.com/redhat-developer/s2i-dotnetcore-persistent-ex#dotnet-9.0 --context-dir appCopy to Clipboard Copied! Toggle word wrap Toggle overflow Add environment variables from the
postgresqlsecret and database service name environment variable:oc set env dc/s2i-dotnetcore-persistent-ex --from=secret/postgresql -e database-service=postgresql
$ oc set env dc/s2i-dotnetcore-persistent-ex --from=secret/postgresql -e database-service=postgresqlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Make the application accessible externally:
oc expose service s2i-dotnetcore-persistent-ex
$ oc expose service s2i-dotnetcore-persistent-exCopy to Clipboard Copied! Toggle word wrap Toggle overflow Obtain the sharable URL:
oc get route s2i-dotnetcore-persistent-ex
$ oc get route s2i-dotnetcore-persistent-exCopy to Clipboard Copied! Toggle word wrap Toggle overflow