AttachToComponentRegistration not called for ASP.Net Core Controllers

78 views
Skip to first unread message

mes...@gmail.com

unread,
Dec 16, 2016, 11:35:14 AM12/16/16
to Autofac
Hi,

I have a Logger module that creates aspnet Controller-specific Logger instances for the constructors of the Controllers.
For this I have something like this:

public class LogModule : Module
{
protected override void AttachToComponentRegistration(IComponentRegistry componentRegistry, IComponentRegistration registration)
{
...
registration.Preparing += InjectViaConstructor;

}
...
}

In the "old" ASP.NET this worked fine, however, using asp.net core, the AttachToComponentRegistration method is not called for Controller types.
For other types it is still called.

Can you please advise how to workaround this? Do I miss some configuration maybe?

Thanks,
Tamas Meszaros

Travis Illig

unread,
Dec 16, 2016, 11:39:39 AM12/16/16
to Autofac, mes...@gmail.com
Try using the "AddControllersAsServices" extension when setting up MVC. Check out this article for a walkthrough:

mes...@gmail.com

unread,
Dec 17, 2016, 4:58:58 AM12/17/16
to Autofac, mes...@gmail.com
Works fine, thanks a lot!
Reply all
Reply to author
Forward
0 new messages