Working with ASP.NET Core

Edit page Last modified: 21 May 2025

In this tutorial, we'll create a value object and use it an ASP.NET Core Web API project.

We'll see how the .NET Runtime uses 'Type Converters' to convert from primitives that are provided by the routing framework into Value Objects that you can then use in your domain code

Type Converters are used by the .NET runtime in things like UI grids, WPF bindings, and ASP.NET Core application.

We'll focus on the latter in this tutorial by creating a new ASP.NET Core Web API and extend the 'weather forecast' endpoint to take a Value Object representing a city name.

Create a new ASP.NET Core Web API targeting .NET 7.0.

Next, in the new project, look at the endpoint named GetWeatherForecast in the WeatherForecastController type.

It looks like this:

Now, add a CityName value object and use it as part of the request.

... now, add this as a parameter to the endpoint:

Add a CityName property to the WeatherForecast type:

Now, change the code in the endpoint to populate the new CityName property. We're keeping things simple and just returning what we were provided:

You can now access that via the URL and treat the value object as a string, e.g. http://localhost:5053/WeatherForecast/London

You should see the City returned, something like this:

return-from-web-api.png