avatarSukhpinder Singh | .Net Developer

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2770

Abstract

h2><ol><li>Set the AspireSample.AppHost project as the startup project in Visual Studio.</li><li>Press F5 to run the app.</li><li>Navigate to the weather page from the home page in your browser to load weather data.</li><li>Continuously refresh the page for 10 seconds to observe cached data retrieval.</li></ol><h2 id="e180">To create a new .NET Aspire Starter Application template via the command line:</h2><p id="44da">Open your command line interface & execute the following command:</p><div id="a51a"><pre>dotnet <span class="hljs-keyword">new</span> -i Microsoft.AspNetCore.Components.WebAssembly.<span class="hljs-title class_">Templates</span>::<span class="hljs-number">5.0</span>.<span class="hljs-number">0</span>-preview.<span class="hljs-number">8.20414</span>.<span class="hljs-number">8</span></pre></div><p id="b307">This command installs the .NET Aspire template for you to utilize.</p><p id="1d55">Once the installation is complete, create a new .NET Aspire Starter Application by executing:</p><div id="e48c"><pre>dotnet <span class="hljs-keyword">new</span> aspire -n AspireSample</pre></div><p id="e89d">This command creates a new project named “AspireSample” using the .NET Aspire template.</p><h2 id="9392">Testing the App Locally:</h2><p id="7c7a">After creating the sample app, proceed to test it locally. Navigate to the project directory using the following command.</p><div id="1c20"><pre><span class="hljs-built_in">cd</span> AspireSample</pre></div><h2 id="f62e">Run the app</h2><div id="5e3f"><pre>dotnet run</pre></div><p id="d583">Access the app through your web browser to ensure it functions as expected.</p><p id="6bb1">🤓 Congratulations! You’ve successfully created and tested your first .NET Aspire application.</p><h2 id="f712">More articles</h2><div id="e3e3" class="link-block"> <a href="https://readmedium.com/group-by-multiple-columns-in-c-data-aggregation-e72c804beb1e"> <div> <div> <h2>Group By Multiple Columns in C#: Data Aggregation</h2> <div><h3>Introduction</h3></div> <div><p>medium.com</p></div> </div> <div> <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*5Uf2ZyWBUZ7UAIPb)"></div> </div> </div> </a> </div><div id="44f3" class="link-block"> <a href="https://readmedium.com/choosing-between-ilogger-ilogger-t-iloggerfactory-and-iloggerprovider-3656daee96cf"> <div> <div> <h2>Choosing Between ILogger, ILogger<t>, ILoggerFactory, and ILoggerProvider</t></h2> <div><h3>Introduction</h3></div> <div><p>medium.com</p></div>

Options

       </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*YXOATUA6FAgsYfYh)"></div>
          </div>
        </div>
      </a>
    </div><div id="4610" class="link-block">
      <a href="https://readmedium.com/differences-and-similarities-dictionary-vs-hashtable-in-c-explained-75c643125bd">
        <div>
          <div>
            <h2>Differences and Similarities: Dictionary vs. Hashtable in C# Explained</h2>
            <div><h3>Gain valuable insights to make informed decisions when choosing the right collection for C# projects.</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*Z3Pe0KKy1HHohCPe)"></div>
          </div>
        </div>
      </a>
    </div><div id="6515" class="link-block">
      <a href="https://readmedium.com/exception-handling-in-c-best-practices-864d5d890ad6">
        <div>
          <div>
            <h2>Exception Handling in C#: Best Practices</h2>
            <div><h3>Exception handling in C# can significantly benefit from improved code readability and maintainability.</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*-dbHzLcqEQDwhHdz)"></div>
          </div>
        </div>
      </a>
    </div><div id="6a96" class="link-block">
      <a href="https://readmedium.com/alternative-to-double-not-c-2eaa86efd68a">
        <div>
          <div>
            <h2>Alternative to double-not(!!)-C#</h2>
            <div><h3>In C#, the double not operator (!!) is not available. Nonetheless, it can be attained comparable functionality by…</h3></div>
            <div><p>medium.com</p></div>
          </div>
          <div>
            <div style="background-image: url(https://miro.readmedium.com/v2/resize:fit:320/0*ElfLZ9fAmwNnDln0)"></div>
          </div>
        </div>
      </a>
    </div><h2 id="6ab7">Follow me on</h2><p id="dcfe"><a href="https://medium.com/c-sharp-progarmming">C# Publication</a>, <a href="https://www.linkedin.com/in/sukhpinder-singh-532284a2/">LinkedIn</a>, <a href="https://www.instagram.com/sukhpindersukh/">Instagram</a>, <a href="https://twitter.com/sukhsukhpinder">Twitter</a>, <a href="https://dev.to/ssukhpinder">Dev.to</a></p><figure id="01a2"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*Dpw8-hNGI2fDmosV4E8DVQ.png"><figcaption></figcaption></figure></article></body>

Get Started: Building Your Initial .NET Aspire App

Creating a .NET Aspire Starter Application for Efficient Cloud-Native Development

Cloud-native applications often necessitate connections to diverse services like databases, storage solutions, messaging platforms, or web services. .NET Aspire simplifies these connections and configurations, facilitating streamlined development processes. This quickstart tutorial demonstrates how to initiate a .NET Aspire Starter Application template solution.

Photo by Mohammad Rahmani on Unsplash

Objectives

Establish a fundamental .NET application configured to utilize .NET Aspire.

  • Integrate and configure a .NET Aspire component to implement caching upon project creation.
  • Develop an API and employ service discovery to establish connectivity.
  • Coordinate communication between a front-end UI, a back-end API, and a local Redis cache.

Prerequisites

Before diving in, ensure the following prerequisites are met:

  • .NET 8.0 installed locally.

.NET Aspire workload

  • Install via Visual Studio installer.
  • Use the dotnet workload install aspire command.
  • Docker Desktop installed.

Creating the .NET Aspire Template

You can create a new .NET Aspire Starter Application using either Visual Studio or the .NET CLI.

Using Visual Studio

  1. Navigate to File > New > Project at the top of Visual Studio.
  2. In the dialogue window, search for “Aspire” and select “.NET Aspire Starter Application”. Proceed to the next step.
  3. Configure your new project by entering a Project Name (e.g., “AspireSample”) and leave other values at their defaults. Proceed to the next step.
  4. Ensure that .NET 8.0 (Long Term Support) is selected and check “Use Redis for caching (requires Docker)”. Finally, select “Create” to finalize.

Testing the App Locally

Once the sample app is created, it’s ready for testing. Verify the following:

  • Weather data is fetched from the API project via service discovery and displayed on the weather page.
  • Subsequent requests are handled via the output caching configured by the .NET Aspire Redis component.

To run the app locally

  1. Set the AspireSample.AppHost project as the startup project in Visual Studio.
  2. Press F5 to run the app.
  3. Navigate to the weather page from the home page in your browser to load weather data.
  4. Continuously refresh the page for 10 seconds to observe cached data retrieval.

To create a new .NET Aspire Starter Application template via the command line:

Open your command line interface & execute the following command:

dotnet new -i Microsoft.AspNetCore.Components.WebAssembly.Templates::5.0.0-preview.8.20414.8

This command installs the .NET Aspire template for you to utilize.

Once the installation is complete, create a new .NET Aspire Starter Application by executing:

dotnet new aspire -n AspireSample

This command creates a new project named “AspireSample” using the .NET Aspire template.

Testing the App Locally:

After creating the sample app, proceed to test it locally. Navigate to the project directory using the following command.

cd AspireSample

Run the app

dotnet run

Access the app through your web browser to ensure it functions as expected.

🤓 Congratulations! You’ve successfully created and tested your first .NET Aspire application.

More articles

Follow me on

C# Publication, LinkedIn, Instagram, Twitter, Dev.to

Dotnet
Dotnet Aspire
Dotnet Core
Csharp
Aspnetcore
Recommended from ReadMedium