Full Trust European Hosting

BLOG about Full Trust Hosting and Its Technology - Dedicated to European Windows Hosting Customer

Visual Studio Hosting - HostForLIFE.eu :: Code cleanup in Visual Studio 2022

clock July 21, 2025 07:49 by author Peter

The Code Cleanup function in Visual Studio 2022 automatically formats and applies code style guidelines to your code. This keeps your codebase readable, maintainable, and clean.

What is Code Cleanup?
Code Cleanup applies refactoring and formatting rules to your code files. It includes:

  • Removing unnecessary usings/Imports
  • Sorting usings/Imports
  • Applying naming conventions
  • Formatting spacing and indentation
  • Converting var to explicit types (or vice versa)
  • Removing unused variables

How to Use Code Cleanup?
1. Using the Toolbar Button

  • Open a C#, VB.NET, or other supported code file.
  • Click the broom icon 🧹 on the bottom-right corner of the editor.
  • There may be two profiles (Profile 1, Profile 2). Click the dropdown arrow to choose or configure a profile.
  • Click the broom icon to run the cleanup.

2. Using a Keyboard Shortcut
Default shortcut: Ctrl + K, Ctrl + E
(You can customize it in Tools > Options > Keyboard).

3. Context Menu
Right-click anywhere in your code editor.
Select Run Code Cleanup

code clean up

Configure Code Cleanup Profiles
Go to: Tools > Options > Text Editor > [Your Language, e.g., C#] > Code Style > Code Cleanup
There are two profiles (Profile 1 & Profile 2). Each can be customized with:

  • Format document
  • Sort and remove usings
  • Apply file header
  • Apply naming rules
  • Remove unnecessary code

Click Configure Code Cleanup to choose what each profile should do.


Run Cleanup on Entire Solution or Project

  • Right-click on the Solution or Project in Solution Explorer.
  • Choose Analyze and Code Cleanup > Run Code Cleanup.

Note: By default, this only formats open documents. To apply it to all files, use a tool like Roslyn analyzers or the dotnet format CLI (for .NET Core/.NET 5+ projects).

Optional Tools for Deeper Cleanup

.editorconfig file: Store consistent code style settings in the repo.
Roslyn Analyzers: Enforce rules across the solution.
Refactoring Suggestions: Lightbulb actions (Ctrl + .)

Conclusion
In this article, I have tried to cover Code cleanup in Visual Studio 2022.



AngularJS Hosting Europe - HostForLIFE :: Communication Between Parent and Child Components: Resolving the Sync Problem

clock July 16, 2025 08:41 by author Peter

Component communication is essential for creating reusable and modular components in Angular. Data is often sent from a parent component to a child component using @Input() and returned using @Output() with an EventEmitter.

The Real Issue
One of our projects involved a parent component passing a selected item ID to a child component via @Input().  The child component used that ID to retrieve and show the details.  However, when the user quickly picked a different item, the kid did not always display the change.  Sometimes it displayed outdated info or didn't update at all.

What Went Wrong
Angular's @Input() only updates when the value changes, but in certain situations (such as when the same ID is passed again after a brief delay), lifecycle hooks like ngOnChanges() failed to detect it. Additionally, ngOnInit() wasn't retriggered on each input change because the child only made one HTTP call.

Solution


We moved the API fetch logic from ngOnInit() to ngOnChanges() and added a proper check for changes:
@Input() itemId!: string;

ngOnChanges(changes: SimpleChanges): void {
  if (changes['itemId'] && changes['itemId'].currentValue) {
    this.loadItemDetails(changes['itemId'].currentValue);
  }
}

loadItemDetails(id: string) {
  this.http.get(`/api/items/${id}`).subscribe(res => {
    this.itemDetails = res;
  });
}


We also added a condition to prevent redundant API calls if the ID hasn’t changed.

Additional Fix
For cases where the same value might be passed again, we manually reset the input before reassigning:
this.selectedItemId = null;
setTimeout(() => this.selectedItemId = item.id, 0);


This trick forces Angular to treat the new input as a different value.

Conclusion
Angular’s @Input() and @Output() work well for component communication, but they don’t always detect subtle changes unless lifecycle hooks are handled properly. Moving logic to ngOnChanges() ensures that child components respond to dynamic data accurately.



Node.js Hosting Europe - HostForLIFE.eu :: What is the architecture of Node.js?

clock July 14, 2025 08:04 by author Peter

It's likely that Node.js is responsible for any websites that load really quickly or change in real time, such as chat apps or live scores. However, what is Node.js and how does its architecture contribute to its power? Let's put it in plain language.

What is Node.js?
Node.js is not a programming language or a framework; it’s a runtime environment. It enables developers to run JavaScript on the server side, outside of the browser. It’s built on Google Chrome’s V8 JavaScript engine, which makes it super fast.

e.g: "Hello World" in Node.js.
// Import the built-in 'http' module
const http = require('http');

// Create a simple server
const server = http.createServer((req, res) => {
  res.end('Hello World from Node.js!');
});

// Server listens on port 3000
server.listen(3000, () => {
  console.log('Server is running on http://localhost:3000');
});

This simple server handles HTTP requests using a single thread and responds with "Hello World". Even if 100 users open it at once, Node.js can manage that efficiently, thanks to its architecture.

Let’s break it down.

1. Single-Threaded Event Loop

Node.js uses a single thread to handle all client requests. That means it doesn’t create a new thread for every request like traditional web servers (such as Apache). Here the question comes.

Then, how does it handle multiple users simultaneously?

It supports multiple users simultaneously through its Event-Driven Architecture. Let's explore it.

2. Event-Driven Architecture

Imagine you are at a restaurant. Instead of the chef cooking only one dish at a time (waiting for it to finish before starting the next), he puts dishes in the oven and moves on to the next task. When the oven beeps, he knows the food is ready.

Our Node.js works in the same way.

  • When a request (like fetching data or reading a file) comes in, it’s added to the event queue.
  • Node.js doesn’t wait for the task to finish. Instead, it moves on to the next task.
  • Once the task is completed, Node.js receives notification (via a callback function) and processes the result.

This makes Node.js extremely fast and efficient, particularly for I/O-Intensive tasks.

  • Reading/writing files
  • Talking to databases
  • Calling APIs

3. Non-Blocking I/O

  • Most web servers use blocking I/O, which means they wait for one operation to finish before moving to the next.
  • Node.js uses non-blocking I/O, meaning it doesn’t wait for input. This allows Node.js to handle thousands of requests per second with a single thread.

Let's simulate a non-blocking operation, such as reading a file.
const fs = require('fs');

console.log('Start reading file...');

fs.readFile('example.txt', 'utf8', (err, data) => {
  if (err) {
    return console.error(err);
  }
  console.log('File content:', data);
});

console.log('Reading file initiated...');


Output

Key Components of Node.js Architecture
Here are the main parts that makeup Node.

Components Role

V8 Engine

Converts JavaScript code into machine code. It’s fast and powerful.

Libuv

A library that provides the event loop and handles asynchronous operations.

Event Loop

Keeps checking for completed tasks and runs their callback functions.

CallBacks

Functions that are executed when a task finishes.

APIs

Node.js provides APIs for file systems, networks, and more.

Advantages of Node.js Architecture
Fast: Thanks to V8 and the non-blocking model.

  • Scalable: Handles a large number of users without crashing or slowing down.
  • Efficient: Great for real-time apps like chat, games, or live data.
  • Lightweight: Uses fewer system resources compared to traditional servers.

When to Use Node.js?
Node.js is ideal for.

  • Real-time apps (chat apps, online games)
  • APIs for web/mobile apps
  • Data streaming apps
  • Single Page Applications (SPAs)

Conclusion
Node.js architecture is what makes it stand out. Its event-driven, non-blocking, and single-threaded design helps developers build fast, scalable, and efficient applications.

HostForLIFE.eu Node.js Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.



AngularJS Hosting Europe - HostForLIFE :: Lazy Loading in Angular: An Issue and Fix in Real Time

clock July 10, 2025 07:49 by author Peter

A common technique for improving performance in large Angular apps is lazy loading. The practice of loading a module only after the user has reached its route is known as lazy loading. This reduces the initial load time of the application. In one of our projects, we had a dashboard module that was loaded slowly. The module worked flawlessly when the app was being used. However, when the user reloaded the browser while on the dashboard route (http://localhost:4200/dashboard), a blank page or 404 error was shown.

Causes of the Issue
Client-side angular routing is used. When you hit refresh, the browser asks the server to fetch that route, but the server is not aware of this.

How Did We Fix It?
We fixed that by instructing the server to divert all requests to index.html so that Angular could handle the routing. In this case, we changed the.htaccess file with the following since we were using an Apache server:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  RewriteRule ^index\.html$ - [L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule . /index.html [L]

</IfModule>


There is no issue if you use the built-in dev server in Angular CLI, as it takes care of this already. However, the hosting server needs to know for production.

Conclusion

App performance is enhanced by lazy loading, but if the server is not set up correctly, it may result in unforeseen problems. To allow Angular to handle routing, always ensure that your server reroutes unknown routes to index.html.



AngularJS Hosting Europe - HostForLIFE :: Angular Lifecycle Hooks: An Understanding

clock July 1, 2025 08:06 by author Peter

Google developed the open-source Angular frontend framework, which is based on TypeScript. It assists developers in creating scalable, contemporary online applications, particularly Single Page Applications (SPAs), in which content updates dynamically rather than requiring a page reload. By employing components and services to arrange our code, it facilitates efficient and maintainable development. We must first establish a clear understanding of Angular's definition, structure, and component placement before lifecycle hooks make any sense.

AngularJS vs Angular (Modern Angular)

Feature AngularJS Angular (2+)
Language JavaScript TypeScript
Architecture MVC Component-based
Mobile Support Poor Excellent
Performance Slower Faster (AOT, Tree Shaking)
Development Support Discontinued Actively maintained
Ecosystem Classic JS ecosystem RxJS, TypeScript, CLI

Here’s how the high-level angular structure looks.

Angular Element Purpose School App Example
Modules Organize the app into functional areas StudentModule, TeacherModule, AdminModule, and TimetableModule group features into manageable sections.
Components Handle UI and logic for individual features StudentListComponent, AttendanceFormComponent, and ExamResultsComponent power the core screens of the app.
Templates Define the view using Angular-enhanced HTML A dynamic report card template uses *ngFor to loop through subjects and display student scores.
Services Share business logic and data access across components StudentService centralizes logic to fetch, add, or update student records from the backend.
Routing Enable navigation between pages Angular Router handles navigation to /students, /teachers, /results, and /library.
Directives Add dynamic behavior to templates *ngIf="isAbsent" highlights students in red if they’re absent during the attendance check.
Pipes Format output in templates {{ dateOfBirth | date:'longDate' }} formats a birthday date

What is a Component in Angular?

The core of the user interface in Angular is a component. Usually, every screen, button, form, or card is implemented as a component, much like the Common Language Runtime (CLR) components in.NET. A component is the fundamental unit of the user interface (UI) in Angular. It holds the HTML template, CSS styling, and TypeScript logic for a view, which is a section of the screen that it controls.

Structure of a Component
1. Class contains the logic and data for the component using TypeScript. And File Extension: .ts
@Component({
  selector: 'app-product',         // We can use <app-product></app-product> in HTML
  templateUrl: './product.html',   // Uses product.html for UI
  styleUrls: ['./product.css']     // Uses product.css for styles
})
export class ProductComponent {    // This class holds logic like product name, price, etc.
  name = 'T-Shirt';
  price = 499;
}


2. Template defines the user interface (UI layout) using HTML. It displays data from the class using Angular's data binding.File Extension: .html
<!-- product.component.html -->
<h2>{{ productName }}</h2>
<p>Price: ₹{{ price }}</p>

3. Style adds styling (colors, fonts, spacing) specific to this component. File Extension: .css or .scss

/* product.component.css */
h2 {
  color: blue;
  font-weight: bold;
}

p {
  font-size: 16px;
}


Why are components important for Lifecycle Hooks?

Lifecycle hooks are embedded within components. So, unless you understand how components are created, rendered, and destroyed, lifecycle hooks won’t mean much. Here’s the flow.

  • Angular initializes a component.
  • Angular runs specific hooks at each stage of that component's life.
  • We use those hooks to run our own logic at the perfect moment (like fetching data, unsubscribing, or calculating total).

Angular Lifecycle Hooks
Lifecycle hooks in Angular are special methods that get called automatically at specific stages of a component’s life, from creation to destruction. Lifecycle hooks let Angular manage the creation, change detection, and destruction of components. This gives us fine control over how and when code runs.

Lifecycle hooks are built-in functions that Angular calls at different moments during a component’s lifetime, like when it's created, updated, or destroyed.
Why Use Lifecycle Hooks?

We use lifecycle hooks to,

  • Run initial setup code (like fetching data when the component loads)
  • Detect changes in inputs
  • Perform cleanup tasks (like clearing timers or unsubscribing from services)
  • Debug the flow of your component.


Hook Name When Called Purpose Usage Example
constructor() When a component instance is created Basic initialization of class members (no Angular bindings yet) console.log('Constructor')
ngOnChanges(changes: SimpleChanges) When @Input() property changes Respond to input property changes this.loadData(changes['userId'].currentValue);
ngOnInit() Once after the first ngOnChanges() Fetch data, initialize bindings this.getDataFromService();
ngDoCheck() Every change detection run Custom change tracking logic detectManualChange();
ngAfterContentInit() After content projected via <ng-content> is initialized Set up logic dependent on projected content console.log('ng-content loaded')
ngAfterContentChecked() After every check of the content projection Respond to changes in projected content validateProjectedTemplate();
ngAfterViewInit() After the component’s view (and child views) are initialized DOM access, @ViewChild operations this.chart.init(this.chartElement.nativeElement);
ngAfterViewChecked() After every check of the component and child views Update logic if template data changes adjustLayout();
ngOnDestroy() Just before Angular destroys the component Cleanup (unsubscribe, clear interval) subscription.unsubscribe();

Conclusion
Understanding Angular’s architecture is essential for building modern, scalable, and maintainable web applications. This article walked through the foundational blocks of Angular, Components, Component Lifecycle Hooks, which provide precise control over how Angular creates, updates, and destroys components.

 



About HostForLIFE.eu

HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes.

We have offered the latest Windows 2016 Hosting, ASP.NET Core 2.2.1 Hosting, ASP.NET MVC 6 Hosting and SQL 2017 Hosting.


Tag cloud

Sign in