views:

144

answers:

1

Hello guys, 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.

+1  A: 

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) { } 
Michael Hedgpeth