Skip to content

Commit

Permalink
Update Vogen version and expand FAQ section
Browse files Browse the repository at this point in the history
The Vogen package reference in the ConsumerTests.csproj file was updated to version 4.0.13 from 4.0.4. Additionally, the FAQ.md file under the docs folder was amended to include information on how to use value objects as parameters in Blazor pages and components. The layout of the tutorial "Working-with-Guids.md" in hi.tree was also slightly rearranged.
  • Loading branch information
SteveDunn committed Jul 16, 2024
1 parent a386393 commit e48a8ef
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/site/Writerside/hi.tree
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<toc-element topic="Home.md"/>
</toc-element>
<toc-element topic="Tutorials.topic">
<toc-element topic="Working-with-Guids.md"/>
<toc-element topic="Installation.md"/>
<toc-element topic="your-first-value-object.md"/>
<toc-element topic="ValidationTutorial.md"/>
Expand All @@ -19,6 +18,7 @@
<toc-element topic="Serialization.md"/>
<toc-element topic="Using-with-JSON.md"/>
<toc-element topic="Working-with-logging-frameworks.md"/>
<toc-element topic="Working-with-Guids.md"/>
<toc-element topic="Working-with-databases.md"/>
</toc-element>
<toc-element topic="how-to-guides.topic">
Expand Down
26 changes: 25 additions & 1 deletion docs/site/Writerside/topics/reference/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -502,4 +502,28 @@ public partial struct CustomerId;
var newCustomerId = CustomerId.FromNewGuid();
```

> To customize the generation of Guids, please see [this tutorial](Working-with-Guids.md)
> To customize the generation of Guids, please see [this tutorial](Working-with-Guids.md)
>
### Can I use value objects instead of primitives as parameters in Blazor pages and components?

You can, but it's not straightforward.
Blazor, unlike ASP.NET Core, doesn't consider type converters.
It passes around and stores parameters as objects,
which means that the casting operators in Blazor are also not considered
(it's not possible to have a cast operator that takes `object` in C#).

There are two solutions:
1. (for components only) - pass the value into the parameter as a value object (parameters can be complex objects)
2. (for pages) override `SetParametersAsync` and convert the primitive to the value object, e.g.

```c#
public override Task SetParametersAsync(ParameterView parameters)
{
if (parameters.TryGetValue<int>("Id", out var x))
{
Id = CustomerId.From(x);
}

...
```
2 changes: 1 addition & 1 deletion tests/ConsumerTests/ConsumerTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</ItemGroup>

<ItemGroup Condition=" '$(UseLocallyBuiltPackage)' == ''">
<PackageReference Include="Vogen" Version="4.0.4" />
<PackageReference Include="Vogen" Version="4.0.13" />
</ItemGroup>


Expand Down

0 comments on commit e48a8ef

Please sign in to comment.