---
title: "What is a generic host in .NET Core?"  
description: "What is a generic host in .NET Core?"  
author: "Ashutosh Patel"  
published: 2023-03-06  
updated: 2023-07-08  
canonical: https://www.mindstick.com/forum/157442/what-is-a-generic-host-in-dot-net-core  
category: "asp.net core"  
tags: ["asp.net", "asp.net core"]  
reading_time: 2 minutes  

---

# What is a generic host in .NET Core?

What is a generic [host](https://yourviews.mindstick.com/view/85456/foreign-direct-investment-fdi-and-its-impacts-on-host-countries) in .NET Core?

## Replies

### Reply by Aryan Kumar

In ASP.NET Core, a generic host is a class that implements the `IHost` interface. The `IHost` interface provides a way to start, handle requests, and shut down an ASP.NET Core application.

The generic host is used to create an ASP.NET Core application that can be run on any platform. This is because the generic host does not depend on any specific platform-specific features.

The generic host is implemented as a class that inherits from the `HostBuilder` class. The `HostBuilder` class provides a way to configure the generic host.

To create a generic host, you can use the `CreateDefaultBuilder()` method. The `CreateDefaultBuilder()` method returns a `HostBuilder` object that is configured with the default settings.

Once you have created a `HostBuilder` object, you can configure it by calling the `Configure()` method. The `Configure()` method takes a delegate as its parameter. The delegate is used to configure the generic host.

To start the generic host, you can call the `Run()` method on the `HostBuilder` object. The `Run()` method will start the generic host and listen for requests.

To shut down the generic host, you can call the `Dispose()` method on the `HostBuilder` object. The `Dispose()` method will shut down the generic host and release any resources that it is using.

Here is an example of how to create a generic host:

C#

```plaintext
using Microsoft.AspNetCore.Hosting;

public class Program
{
    public static void Main(string[] args)
    {
        // Create a default host builder
        var builder = HostBuilder.CreateDefaultBuilder();

        // Configure the host builder
        builder.Configure(app =>
        {
            // Set the host name
            app.HostName = "localhost";

            // Set the port number
            app.Port = 8080;
        });

        // Create the host
        var host = builder.Build();

        // Start the host
        host.Run();
    }
}
```

This code will create a generic host that is configured to listen for requests on port 8080. The host will start and listen for requests until it is shut down.


---

Original Source: https://www.mindstick.com/forum/157442/what-is-a-generic-host-in-dot-net-core

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
