Interceptor on registered type

97 views
Skip to first unread message

Hans Santens

unread,
Sep 7, 2011, 5:35:56 AM9/7/11
to aut...@googlegroups.com
Hi,

Let's say I have a class "MyClass"  with an interface "IMyClass".
First I register by type: builder.RegisterType<MyClass>().As<IMyClass>().SingleInstance();
Then I want to add some interceptors to all types of my assembly (or namespace)
So first I register the interceptor itself:
builder.RegisterType<CachingInterceptor>().AsSelf();

Ben then I have a problem. If I use
builder.RegisterAssemblyTypes(typeof(MyClass).assembly).EnableClassInterceptors().InterceptedBy(typeof(CachingInterceptor)
it re-registers all the types in the assembly, even if they where registered in another way before. Ans it seems to me thaht whhen you want to resolve a type, you will get an intance of the latest registration.

So basically my question is:
Is it possible to add interceptors to a type (or all types in an assembly) that is already registered, without re-registering it.


Any feedback would be nice.
Thanks 

Nicholas Blumhardt

unread,
Sep 7, 2011, 8:59:44 AM9/7/11
to aut...@googlegroups.com
Hi Hans,

No - component registrations are always additive, as you've observed. You'll need to add the InterceptedBy() call to the original registration to make this work.

Hope this helps,

Nick

--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To view this discussion on the web visit https://groups.google.com/d/msg/autofac/-/eTx_qbEqs2AJ.
To post to this group, send email to aut...@googlegroups.com.
To unsubscribe from this group, send email to autofac+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/autofac?hl=en.

Hans Santens

unread,
Sep 7, 2011, 9:06:47 AM9/7/11
to aut...@googlegroups.com
Hi

Thanks for your reply. At least now I know I don't have to search any longer :)

Hans
Reply all
Reply to author
Forward
0 new messages