firstly, thank you both for your quick replies; your answers confirmed my suspicion.
Krzysztof, There actually was no reason why I was using a factory method in my code. I've finally gotten an opportunity to introduce a DI container into the code base at work, and I was evaluating the flexibility of Windsor versus other popular DI containers. I'm very impressed by the way ;-) at the same time, I wanted to understand how interceptors worked, and initially found it strange that the line above didn't work. However, after a little thought, I could understand why. I will take your advice and post a suggestion for the feature. Thanks again. Vinay On Mar 25, 5:06 am, Krzysztof Koźmic (2) <[email protected]> wrote: > Vinay, > > Why are you using factory in the first place? > As outlined by Bailey when you create component yourself you take > complete control over its shape, this includes proxying it. > We might add this ability you're asking for (please feel free to add > this suggestion tohttp://castle.uservoice.com/forums/38955-windsor-v3 > ) > but currently it does not work like that. > > Whenever possible it is advised to let the instantiation of your > components to Windsor, and resort to factories only when you have no > other option. > > As a sidenote, for static dependencies (that is dependencies known > upfront like number 5 in your example) it is advised to use DependsOn, > rather than DynamicParameters > > cheers, > > Krzysztof > > On 24 Mar, 23:29, Bailey Ling <[email protected]> wrote: > > > > > the factory facility bypasses the normal way of creating instances, so by > > doing that you're basically preventing windsor from creating a proxy. what > > you wanna try is use kernal.ProxyFactory and create your proxy manually > > within the factory delegate/method. > > > On Wed, Mar 24, 2010 at 2:38 PM, Vinay Mandy <[email protected]> wrote: > > > Hello, > > > > I'm having trouble with the following statement: > > > > container.Register(Component.For<ISomeService>().UsingFactoryMethod(() > > > => new > > > > SomeServiceImpl(5)).Interceptors(InterceptorReference.ForType<SomeServiceIn > > > terceptor>()).First); > > > > whenever I call the 'DoSomething' method on my resolved service, I get > > > the following DP error: > > > > System.NotImplementedException: This is a DynamicProxy2 error: the > > > interceptor attempted to 'Proceed' for method 'Int32 > > > DoSomething(Int32)' which has no target. When calling method without > > > target there is no implementation to 'proceed' to and it is the > > > responsibility of the interceptor to mimic the implementation (set > > > return value, out arguments etc) > > > > I noticed that I don't have the problem if I avoid using a factory > > > method to create my service, like so: > > > > container.Register(Component.For<ISomeService>().ImplementedBy<SomeServiceI > > > mpl>().DynamicParameters((kernel, > > > parameters) => parameters["param"] = > > > > 5).Interceptors(InterceptorReference.ForType<SomeServiceInterceptor>()).Fir > > > st); > > > > Is there any reason that the first approach wouldn't work or is not > > > suggested? Is there an alternative statement that I should use? > > > > Thanks for your help > > > > Vinay > > > > -- > > > You received this message because you are subscribed to the Google Groups > > > "Castle Project Users" group. > > > To post to this group, send email to [email protected] > > > . > > > To unsubscribe from this group, send email to > > > [email protected]<castle-project-users%2Bun > > > [email protected]> > > > . > > > For more options, visit this group at > > >http://groups.google.com/group/castle-project-users?hl=en. -- You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/castle-project-users?hl=en.
