class Factory<Product> where Product : new() { public Factory() : this(() => new Product()) { } public Factory(System.Func<Product> build) { this.build = build; } public Product Build() { return build(); } private System.Func<Product> build; } In Factory, when Product has a public default constructor, I'd like for clients to not have to specify how to construct one (via the first constructor). However I'd like to allow situations where Product does not have a public default constructor (via the second constructor).
Factory's generic constraint is required to allow the implementation of the first constructor, but it prohibits use with any class without a public default constructor.
Is there a way to allow for both?