Introducción a .NET

CLR (Common language runtime)

Entorno de ejecucion para .NET. En tiempo de ejecucion el compilador de CLR convierte el codigo CIL en codigo nativo para el SO. Facilita la integración entre lenguajes.

CLR es la MV en la que se ejecutan nuestras apps. CLR se hizo para tener una capa de abstraccion entre las propias apps y el SO donde se ejecutaban.

El CLI se puede ejecutar en otros SO. El CLR se ejecuta solo en Windows.

.NET intro

Read More

.NET launchsettings vs appsettings

launchSettings

Tiene más que ver con el despliegue. Establece los perfiles con los que ejecutaremos nuestro proyecto. Configura la forma en la que se inicia la aplicación durante el desarrollo.

No se utiliza en entornos de producción.

appsettings

Se utiliza para almacenar la configuración de la aplicación, como cadenas de conexión de BBDD.

Se utiliza tanto en entornos de desarrollo como de producción.

Dependency injection in .NET Core

Disponible de forma nativa en .NET Core.

Implementación DI

interfaz de la cual se hace la DI

public interface IVehiculoService
{
	Vehiculo GetVehiculo(int id);
	
	string Arrancar();
}

implementación de la interfaz

public class VehiculoService: IVehiculoService
{
	public Vehiculo GetVehiculo(int id)
	{
		// consulta y retornar de BBDD
		return new Vehiculo();
	}

	public string Arrancar()
	{
		return "Arrancando";
	}
}

Read More

.NET Middleware

Middleware is software assembled into a pipeline to handle request and responses. Each component:

  • Chooses if he passes the request to the next component.
  • Can perform work before and after the next component.

(an example can be an authorization middleware)

.NET middleware

Test APIs with Postman - Scripting

We can set pre-request scripts (run before the request) & tests (after execution) at several levels:

  • Collection
  • Folder
  • Request

Snippets

Inside pre-request Script and Tests we have a SNIPPETS column with templates we may use for our code.

postman scripting

Get / Set variables

console.log("Hello world");

// work with local vars
let urlVar = pm.variables.get("protocol");
console.log("value for protocol: " + urlVar);

pm.variables.set("protocol", "http");
console.log(pm.variables.get("protocol"));  

// work with global vars
let globalVar = pm.globals.get("env");
console.log(globalVar);

Read More

Test APIs with Postman - GUI

To test postman I use https://reqres.in. You can use it to learn how to write Postman tests.

Collections

Collections have metadata which you can set up. This includes:

  • Authorization so you don’t need to set it for every single request.
  • Variables, for variables only for this collection (so you don’t use environment vars).
  • Collection tests.

postman gui

Read More

Error al crear imagenes en local (Minikube)

Hay un problema al intentar correr una imagen tuya propia en local con minikube. Minikube tiene su propio repositorio de imagenes y si no encuentra una imagen alli, la intenta descargar siempre del repositorio.

Solución

Set imagePullPolicy: IfNotPresent

error crear imagenes minikube en local

Run the following command:

eval $(minikube docker-env)
# build again the image
# try to run it again

Reference(s)

https://medium.com/bb-tutorials-and-thoughts/how-to-use-own-local-doker-images-with-minikube-2c1ed0b0968

K8s download logs from pod

There are two ways to access Pod logs.

Console Logs

If the logs are being written into the console Pod

kubectl logs connector-5f84b9d984-mggjg > test-file.log

File Logs

If logs are being written into an internal file, we may download it

kubectl -n aks-dev cp connector-5fb7574d94-2npvk:/usr/src/app/logs/CONNECTOR-2024-05-02.log log-connector-02.log

Read More

K8s debug pod errors

See pod details (filtered)

see most important pod details

kubectl describe pod {name_of_your_pod_here}

(at the end where the events are, we see the image it is trying to use doesn’t exist).

kubernetes debug pod 1

get YAML

kubectl get pod {pod_name_goes_here} -o yaml

Read More

K8s commands quickguide

Config

Azure

log-in into a tenant

az login --tenant 7f2c3a6b-e849-4d6f-b65d-1c0ef8b0f41c

configure local kubectl .kube config file

az aks get-credentials --resource-group my-aks --name aksname --admin

(the –admin part is optional but useful)

Contexts & Namespaces

see all configured contexts

kubectl config get-contexts

configure a context with a default namespace

kubectl config set-context <context_here> --namespace=<namespace_here>
# example
kubectl config set-context my-aks-context --namespace=aks-dev

Read More