C#C
C#10mo ago
Victor H

Generic static factories

Hello. I have the following interface:

public interface IStronglyTypedId<TValue, out TSelf>
    where TSelf : IStronglyTypedId<TValue, TSelf>
{
    TValue Value { get; }
    static abstract TSelf From(TValue value);
}


This works well but I want to have a specific type of strongly typed id's of type AggregateId which must have an underlying backing type of Guid, especially a version 7 guid. So basically how can I have default implementations for abstract records?

I tried this but infinite recursion.
public abstract record AggregateId<TId>(Guid Value) : IStronglyTypedId<Guid, TId>
    where TId : IStronglyTypedId<Guid, TSelf>
{
    public static TSelf From(Guid value) => TSelf.From(value); // <- infinite recursion
}
Was this page helpful?