By default, Caliburn Micro uses the MEF. And, by default, the MEF uses attributes to identify components.
I’m pretty lazy and, given the choice, I’d rather use conventions and auto-registration. Luckily someone else was way ahead of me! And the MEFContrib project contains all the building blocks you need to create your own conventions.
I was originally planning on implementing a convention to register the first declared interface but, due to the vagaries of reflection, I took the easy way out and registered all interfaces from the same assembly (did I mention I’m lazy?).
public class AppPartRegistry : PartRegistry { public AppPartRegistry() { this.Part().RegisterAllInterfaces(); this.Scan(c => c.Assembly(typeof(AppPartRegistry).Assembly)); } } public static class PartConventions { public static void RegisterAllInterfaces(this PartConventionBuilder<PartConvention> builder) { builder .ForTypesMatching(t => true) .ImportConstructor() .MakeNonShared() .Exports(e => { e.Export().Members(t => t.GetInterfaces().Where(i => i.Assembly == t.Assembly).ToArray()); }); } }
Update: Import (greediest) ctor, and make registrations transient.