Is there a way to ask Autofac to automatically register all Windows Forms in my assembly? This feature would most likely be similar to the Autofac MVC support's ability to register all controllers?
Right now, I do:
foreach (var type in Assembly.GetExecutingAssembly().GetTypesSafely().Where(type => type.IsSubclassOf(typeof(Form))))
builder.RegisterType(type);
Here's a short and sweet way of doing it:
var assembly = Assembly.GetExecutingAssembly();
builder.RegisterAssemblyTypes(assembly)
.AssignableTo<Form>();
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