I have a generic IRepository that has 2 constructors, one have none parameters, other has the datacontext as parameter. I want to define to structuremap to aways in this case use the parameterless constructor. I want a way to create a parameterless contructor, other solutions that I have seen, they create a new Datacontext and pass it to the constructor that has parameters.
By default, StructureMap will use the constructor with the most arguments. In your case, since you want it to use the parameterless constructor, use the DefaultConstructorAttribute
:
[DefaultConstructor]
public void Repository<T>() { }
public void Repository<T>(DataContext dataContext) { }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With