I have the following two classes:
public class KeyedEntity<TEntity>
{
internal KeyedEntity() { }
public Identifier Key { get; set; }
public TEntity Entity { get; set; }
}
public static class KeyedEntity
{
public static KeyedEntity<TEntity> Create<TEntity>(Identifier key, TEntity entity)
{
return new KeyedEntity<TEntity>
{
Key = key,
Entity = entity,
};
}
}
The reason the constructor is internal and the second class exists is I want to enforce the more highly-maintainable KeyedEntity.Create(x, y) syntax rather than new KeyedEntity<T>{ Key = x, Entity = y }. (Note that the type is inferred with the former syntax.)
I want to tell AutoFixture how to create an instance of KeyedEntity. However, the Register method only seems to allow registration of a single type rather than an open generic type.
How can I register KeyedEntity.Create<TEntity> as the creation function for KeyedEntity<TEntity>?