How to do polling with RxJs and Angular? | by Alain Chautard | Angular Training

In this tutorial, we’re going to implement a polling mechanism using RxJs and Angular. Our goal is to retrieve and render information that gets refreshed periodically. Our example is going to be a currency service that displays up-to-date currency exchange rates

Source: How to do polling with RxJs and Angular? | by Alain Chautard | Angular Training

Async pipe syntax tricks

What if I need to read multiple properties from the object in that subscription?

Another way to put it is that you don’t want to end up doing something like this:

<p>First name: {{ (user$ | async)?.firstName }}</p>
<p>Last name: {{ (user$ | async)?.lastName }}</p>Code language: HTML, XML (xml)

The above code is pretty hard to read and requires one subscription for each property. This alone can be a disaster, as each subscription might trigger an HTTP request for the same data from the server!

Instead, you can do something like this, which uses only one subscription, stores the result in a local variable, then renders the data when it’s available. This technique works with any structural directive, such as *ngIf or *ngFor:

<div *ngIf="user$ | async as user">
   <p>First name: {{ user.firstName }}</p>
   <p>Last name: {{ user.lastName }}</p>
</div>

Source: Async pipe syntax tricks | Angular Newsletter

First Official OpenAI Library for .NET Goes Beta — Visual Studio Magazine

Although it seems Microsoft and OpenAI have been deeply intertwined partners for a long time, they are only now getting around to releasing an official OpenAI library for .NET developers, joining existing community libraries.

The first beta of the effort is an OpenAI NuGet package supporting .NET 6 and .NET Standard 2.0, now at version 2.0.0-beta.2 and listing some 868,000 downloads.

visualstudiomagazine.com/Articles/2024/06/07/openai-net.aspx

Setup Azure Application Insights for a .NET Core API 8 application

Create an Application Insights Resource in Azure:

– Go to the Azure portal, “Create a resource”, search for “Application Insights” and create.

Install the Application Insights SDK in Your .NET Core 8 Project:

– Open your .NET Core API project.

– Install the `Microsoft.ApplicationInsights.AspNetCore` NuGet package

Configure Application Insights in Your Project:

– Open the `appsettings.json` file and add your Application Insights Instrumentation Key:

{
       "ApplicationInsights": {
         "InstrumentationKey": "your_instrumentation_key_here"
       }
}

The instrumentation key can be found in azure portal on the application insight resource “Overview tab”, the label “Instrumentation Key” in top right.

– Alternatively, you can set the instrumentation key in the environment variables.

Add the Application Insights telemetry

Modify the `Program.cs` file:

using Microsoft.ApplicationInsights.Extensibility;
...

// Add Application Insights telemetry
builder.Services.AddApplicationInsightsTelemetry();

// Configure logging to include Application Insights
builder.Logging.AddApplicationInsights();

//Write log message
var logger = builder.Services.BuildServiceProvider().GetRequiredService<ILogger<Program>>();
logger.LogInformation("Logging init");
...

var app = builder.Build();
//Write log message to indicate logging is working
app.Logger.LogInformation("Logging init");
...

Set logging level to information and add logging message:

Default logging level for Application Insights logger is “warning”, here is how to change the level to include “information” as well.

Method 1
: in appsettings.json file:

{
...
  "Logging": {
    "LogLevel": {
...
    },
    "ApplicationInsights": {
      "LogLevel": {
        "Default": "Information",
        "Microsoft": "Warning",
        "Microsoft.Hosting.Lifetime": "Information"
      }
    }
  }
}

Method2: Configure Logging Level in Program.cs

// Add Application Insights telemetry
builder.Services.AddApplicationInsightsTelemetry();

// Configure logging to include Application Insights
builder.Logging.AddApplicationInsights();

// Set the logging level to Information
builder.Logging.AddFilter<Microsoft.Extensions.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider>("", LogLevel.Information);

Verify Telemetry Collection logging

– Run your application, the logging “Logging init” should have been logged.

– Go back to the Azure portal, navigate to your Application Insights resource, and check the “Live Metrics Stream” or “Logs” to verify that telemetry data  is being collected. E.g. filter for “traces” in the query and the “Logging init” LogInformation() call should be present.

Example log query:

traces 
 | where message has "init"

Example of more advanced log query:

traces
| where timestamp > ago(2h) // Adjust the time range as needed
| where severityLevel >= 1 // 1 corresponds to Information level and above
| project timestamp, message, severityLevel
| order by timestamp desc

Set the timestamp presentation to Swedish time

If you are in non English country you might want to change the time presentation and the local time zone default settings.

Set regional format for Azure Portal:
Click the user menu in top right: select “View account”:

Select “settings..” tab, set regional format and time zone.

Set local time zone as default for the log view:

 

 

Angular and Wiz Are Better Together

You may know Angular as the web framework from Google, but Google actually has another web framework: Wiz. Both Angular and Wiz are used by thousands of engineers and thousands of apps inside of Google. Wiz is an internal framework that is used by some of the most popular Google products such as SearchPhotosPayments and many others. Over the last year we’ve been exploring ways for Angular to benefit from the performance of Wiz and Wiz to benefit from the developer experience of Angular.

Welcome to Pathways – Your first step toward developing for Apple platforms

Welcome to Pathways Your first step toward developing for Apple platforms. Pathways are simple and easy-to-navigate collections of the videos, documentation, and resources you’ll need to start building great apps and games. They’re the perfect place to begin your Apple developer journey — all you need is a Mac and an idea.
developer.apple.com/pathways/

Host and deploy Angular web app using Azure and Github

I am using Angular v17 and node v18.
In simple steps;
Goto azure portal.
Create a new resource of type “Static Web App”
I choose Github as Deployment source.

Regarding Angular v17, I had problems with the github deployment build actions:

  • Node was configured as v16 but angular v17 needs node v18
  • path to index.html for dist build could not be found

After Azure has created the static web app for Github deployment the following file is pushed into the repo:

.github/workflow/azure-static-web-apps-[*].yml

I hade to set the following values correctly:

app_location: "./" # App source code path
output_location: "./dist/gps-tracker/browser" # Built app content directory - optional

The output location should point to where the index.html file is located.
You should change the ‘gps-tracker’ to your application name. To find out exactly run ‘ng build’ locally and look into the created dist folder.

Regarding setting node version to 18: I added the following in the yml file:

env:
  NODE_VERSION: '18.x'

Print screen of node version setting:

Clean Architecture in .NET

Layers in Clean Architecture

Summary

Jason Taylor gives a superb explanation of Clean Architecture on this clip.

Domain and Application are central to the design. It’s the core of the system.

Presentation and Infrastructure belong to the outermost layer and are not dependent on each other. They only depend on Application.

Application only depends on Domain.

Domain has no dependencies.

Source: Clean Architecture. Jason Taylor gives a superb explanation… | by Oscar Olsson | Medium

.NET Managing Dependencies in Your Codebase: Top Tools and Best Practices

As software projects get more complex, managing dependencies becomes an increasingly critical task for developers. Dependencies, the external packages or libraries that your project relies on, can significantly impact your application’s security, maintainability and compatibility. This is particularly true in the .NET ecosystem, where projects often rely on a vast array of NuGet packages.
vslive.com/Blogs/News-and-Tips/2024/03/Managing-Dependencies.aspx?oly_enc_id=5912A0582689D0Y