When you are using a convention registration like Classes
, you cannot call unitary methods like SetDefault
directly; that wouldn't make sense since you're returning a collection of elements, all of which cannot be the default one. (To be more precise, the convention lets you declare descriptions of the components that interest you; the type used is a BasedOnDescriptor
. The IsDefault
method exists on the ComponentRegistration
class)
However it is possible to call a Configure
method (and its variations ConfigureIf
and ConfigureFor
) that lets you call unitary methods on a component. So you could call the IsDefault
using the Configure
method
var regs = Classes
.FromThisAssembly()
.Pick()
.WithServiceAllInterfaces(); // dummy registration
regs.Configure(c => c.IsDefault());
Of course you would need to define how the default component is determined. For example if the default component name contains the word "default"
you may use the ConfigureIf
method:
regs.ConfigureIf(component => component.Name.ToLower().Contains("default"),
component => component.IsDefault());