Closed GoogleCodeExporter closed 8 years ago
I'm not sure we can do that. Just speaking personally, I know I have
applications where I explicitly register controllers, so I never call the
RegisterControllers extension. If we added a checker to ensure it was called,
then my apps would fail (as, potentially, would other peoples' apps).
We can't really even require that *any* controllers be registered since,
technically, the default controller activator can fall back and use
Activator.CreateInstance if the controllers aren't registered. It wouldn't make
a lot of sense if you *didn't* register your controllers in Autofac, but I'm
not sure we should *mandate* it by throwing an exception, either.
What I might suggest if you want that behavior in your application:
Derive from AutofacDependencyResolver and, during construction, check to see if
any controllers are registered; if not, throw. (You'd have to do it on
dependency resolver construction since there's no hook into the setting of
resolvers in MVC or WebAPI.) You might have to check for a specific expected
controller, or you could pass in the assembly and ensure that every controller
from a given assembly is registered.
I'm going to close this for now; if you have an update or if I'm
misunderstanding, do let me know.
Original comment by travis.illig
on 28 May 2013 at 4:11
Original issue reported on code.google.com by
simon.cropp@gmail.com
on 24 May 2013 at 12:30