A base implementation of strongly typed ids that supports Newtonsoft.Json, System.Text.Json, EntityFramework Core, and Swashbuckle.AspNetCore.
Package Manager : Install-Package Len.StronglyTypedId
CLI : dotnet add package Len.StronglyTypedId
[StronglyTypedId]
public partial record struct OrderId(Guid Value);
or
[StronglyTypedId]
public partial record OrderId(Guid Value);
Note: Only the record type is supported and cannot be nested, abstract, or generic.Support for serialization and deserialization of Newtonsoft.Json(version 13.0.0 or above) and System.Text.Json.
Add the converter for a strongly typed id to the configuration of DbContext.
protected override void ConfigureConventions(ModelConfigurationBuilder configurationBuilder)
{
base.ConfigureConventions(configurationBuilder);
//...other
StronglyTypedIds.ApplyTo(configurationBuilder);
}
Add the converter for a strongly typed id to the configuration of Swagger.
services.AddSwaggerGen(options =>
{
StronglyTypedIds.ApplyTo(options);
});
Question: Why has the analyzer in the library dependent on strongly-typed IDs not generated the latest code?
Answer: It could be due to the Visual Studio cache. Please clean the solution and regenerate it. Alternatively, you can disregard this situation, as the compiled assembly will include the latest code.