C# tricks – Debugging Complex Classes with the [DebuggerDisplay] Attribute

Debugging complex trees of objects can be difficult even with great debugging tools. In order to make it easier on yourself, consider adding the DebuggerDisplay attribute to those difficult-to-debug classes. DebuggerDisplay allows you to provide a view of your object in the Visual Studio debugger windows that have exactly the data you need to see in order to fix your problems.
vslive.com/Blogs/News-and-Tips/2024/10/Debugging-Complex-Classes-with-the-DebuggerDisplay-Attribute.aspx

Microsoft SQL Server – show total size allocated in MB per table

To get an overview of total disk space allocated per table in MB, use this SQL script:

WITH TableSizes AS
(
    SELECT 
        sch.name AS SchemaName,
        t.name AS TableName,
        SUM(p.rows) AS RowCounts,
        SUM(a.total_pages) * 8 AS TotalSpaceKB, 
        SUM(a.used_pages) * 8 AS UsedSpaceKB,
        (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
    FROM 
        sys.tables t
    INNER JOIN 
        sys.indexes i ON t.object_id = i.object_id
    INNER JOIN 
        sys.partitions p ON i.object_id = p.object_id AND i.index_id = p.index_id
    INNER JOIN 
        sys.allocation_units a ON p.partition_id = a.container_id
    INNER JOIN 
        sys.schemas sch ON t.schema_id = sch.schema_id
    WHERE 
        t.type = 'U' -- Only include user tables
    GROUP BY 
        sch.name, t.name
)
SELECT 
    SchemaName,
    TableName,
    RowCounts,
    --TotalSpaceKB,
    --UsedSpaceKB,
    --UnusedSpaceKB,
    CAST(TotalSpaceKB / 1024.0 AS DECIMAL(10, 0)) AS TotalSpaceMB
    --CAST(UsedSpaceKB / 1024.0 AS DECIMAL(10, 2)) AS UsedSpaceMB,
    --CAST(UnusedSpaceKB / 1024.0 AS DECIMAL(10, 2)) AS UnusedSpaceMB
FROM 
    TableSizes
ORDER BY 
    TotalSpaceKB DESC;

 

How to debug Angular component test Dependency Injection chain

When running ng test (Angular component testing) and you get this type of error:

[Service1 -> Service2 -> Service3]: NullInjectorError: No provider for Service3!

And you dont really understand which component, service or directive that is starting this DI chain. Here is a way to debug and hopefully find the source of the problem:

In Edge/Chrome: when in karma runner page, open devtools (f12), on source tab, select both “Pause on uncaught/caught exceptions”

Reload the test, step into a few times, you should be able to get the call stack as in picture above. Here we can deduce that DI chain starts with a component html template, which uses a translate directive in markup, which calls DictionaryService which calls UserAppDataQueryService which calls AuthenticationService.

Tip: run all spec files below a certain folder like this:

ng test --include "src/app/myarea/**/*.spec.ts" --browsers=Edge

Tip2: run a single spec file:

ng test --include "src/app/myarea/**/mytest.component.spec.ts" --browsers=Edge

 

How to run Angular component tests (karma) for a certain folder or specific spec file

This runs all spec files that are descendants of the “my-area” folder and in the “Edge” browser.

ng test --include "src/app/my-area/**/*.spec.ts" --browsers=Edge

run a single spec file:

ng test --include "src/app/myarea/**/mytest.component.spec.ts" --browsers=Edge

Angular v19 will make components as standalone default

Angular v19 will make standalone: true the default for components, directives, and pipes.In v14 we introduced a developer preview “standalone” feature, which made it possible for the first time to build an application that didn’t rely on NgModules. Since then, standalone has been stabilized, and has become the recommended way to write Angular code by the Angular team. The CLI generates components with standalone: true by default, and the Angular docs teach standalone first to all new Angular developers. A

Source: The future is standalone!. Angular v19 will make standalone: true… | by Alex Rickabaugh | Sep, 2024 | Angular Blog

Basic form validation with Angular – provide visual feedback with form changes CSS classes

Validating user input in HTML forms can be a tedious task. In this new series, we’ll look at how Angular can help us implement painless form validation. First, it’s essential to know that Angular relies primarily on native browser validation features that use modern HTML properties. For instance, if a form field has to be filled out, you can mark it as required using the required HTML attribute

Source: Basic form validation with Angular | Angular Newsletter

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