Tricky one. I think it's line 342 of the RegistrationBuilder<T, A, R> that's the culprit, the one where the ActivatingEventArgs gets created:
public IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> OnActivating(Action<IActivatingEventArgs<TLimit>> handler){if (handler == null) throw new ArgumentNullException("handler");RegistrationData.ActivatingHandlers.Add((s, e) =>{var args = new ActivatingEventArgs<TLimit>(e.Context, e.Component, e.Parameters, (TLimit)e.Instance);handler(args);e.Instance = args.Instance;});return this;}
On Thursday, April 25, 2013 8:34:54 AM UTC-7, Kaleb Pederson wrote:I just tested and the behavior occurs in both autofac 2.6 and 3.0. I also created a complete unit test and posted to Stack Overflow:Thanks.--KalebOn Wed, Apr 24, 2013 at 4:43 PM, Kaleb Pederson <kaleb.p...@gmail.com> wrote:
Using Autofac-2.6.I'm trying to decorate an object in the following fashion:public interface ISample {}public class Sample : ISample {}public class ProxiedSample: ISample {/*with constructor*/}builder.RegisterType<Sample>().As<ISample>().OnActivating(e => e.ReplaceInstance(new ProxiedSample(e.Instance)));That results in an exception though:System.InvalidCastException : Unable to cast object of type 'ProxiedSample' to type 'Sample'.Is there a variant of the registration above that will allow me to proxy it based on the interface type instead of the concrete type?Note: I know there's the RegisterDecorator method but I have some other things going on in this case that make it less than ideal, especially given its key requirements.Thanks.--Kaleb
--
You received this message because you are subscribed to the Google Groups "Autofac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to autofac+u...@googlegroups.com.
To post to this group, send email to aut...@googlegroups.com.
Visit this group at http://groups.google.com/group/autofac?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks Kaleb. That looks like a very simple workaround. I have updated the tag on the page to Autofac3.