Hi Jochen,

The reason why you're seeing this issue is as follows:

* You're registering Automapper's ConfigurationStore class in the container
* The class has (among others) the following two publicly settable properties: public Func<string, string> SourceMemberNameTransformer { get; set; } public Func<string, string> DestinationMemberNameTransformer { get; set; } * With default settings Windsor treats publicly settable properties as optional dependencies that it will try to satisfy * TypedFactoryFacility is the one providing values for those dependencies, injecting delegate-based typed factories into those properties * Automapper thinks you're overriding its defaults and will call those injected Func typed factories, which will trigger Windsor to resolve 'string' service, which is why it fails.

So the problem is twofold:

1. You're exposing those properties in the container. You can chose not to do it by specifying the following when registering the component:
                    .Properties(PropertyFilter.IgnoreAll)
This will make your tests pass.

2. Typed factory facility should ignore Func<string> since Windsor does not allow services of type string anyway. This is a bug in the facility, please report it to the issue tracker.

@K

On 17/02/2012 9:54 PM, Jochen Jonckheere wrote:
Hi,

Recently I tried to update to Windsor 3.0 in my project. Everything compiled, but when I started running my AutoMapper mappings that are also registered in the container couldn't be resolved anymore. When I first tried to isolate the code in a new project, it worked. But then I added the TypedFactoryFacility and bang, exception.

This gist contains all the code needed to reproduce the problem: https://gist.github.com/1852705#file_windsor_automapper_test_fixture.cs

And here is the exception:

Castle.MicroKernel.ComponentActivator.ComponentActivatorException : 
ComponentActivator: could not instantiate WindsorAutoMapper.DummyMapper
  ----> System.Reflection.TargetInvocationException : Exception has been thrown 
by the target of an invocation.
----> Castle.MicroKernel.ComponentNotFoundException : *No component for supporting the service System.String was found*

at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstance(CreationContext context, ConstructorCandidate constructor, Object[] arguments) at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.InternalCreate(CreationContext context) at Castle.MicroKernel.ComponentActivator.AbstractComponentActivator.Create(CreationContext context, Burden burden) at Castle.MicroKernel.Lifestyle.AbstractLifestyleManager.CreateInstance(CreationContext context, Boolean trackedExternally) at Castle.MicroKernel.Lifestyle.SingletonLifestyleManager.Resolve(CreationContext context, IReleasePolicy releasePolicy) at Castle.MicroKernel.Handlers.DefaultHandler.ResolveCore(CreationContext context, Boolean requiresDecommission, Boolean instanceRequired, ref Burden burden) at Castle.MicroKernel.Handlers.DefaultHandler.Resolve(CreationContext context, Boolean instanceRequired) at Castle.MicroKernel.DefaultKernel.ResolveComponent(IHandler handler, Type service, IDictionary additionalArguments, IReleasePolicy policy) at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy)
at Castle.Windsor.WindsorContainer.Resolve()
at WindsorAutoMapper.WindsorAutomapperTestFixture.DummyMapperCanNotBeResolvedIfTheTypedFactoryFacilityIsRegistered() in WindsorAutomapperTestFixture.cs: line 64 <projectfile:20C263C0-C7BB-4EC9-8922-93F433E8A561%2Ff%3AWindsorAutomapperTestFixture.cs%3F64%3F1>
--TargetInvocationException
at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, ref SignatureStruct sig, MethodAttributes methodAttributes, RuntimeType typeOwner) at System.Reflection.RuntimeConstructorInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.MethodBase.Invoke(Object obj, Object[] parameters)
at Castle.MicroKernel.ComponentActivator.DefaultComponentActivator.CreateInstanceCore(ConstructorCandidate constructor, Object[] arguments, Type implType)
--ComponentNotFoundException
at Castle.MicroKernel.DefaultKernel.Castle.MicroKernel.IKernelInternal.Resolve(Type service, IDictionary arguments, IReleasePolicy policy) at Castle.Facilities.TypedFactory.TypedFactoryComponentResolver.Resolve(IKernelInternal kernel, IReleasePolicy scope) at Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Resolve(IInvocation invocation) at Castle.Facilities.TypedFactory.Internal.TypedFactoryInterceptor.Intercept(IInvocation invocation)
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Proxies.Func`2Proxy.Invoke(String arg)
at AutoMapper.TypeMapFactory.<>c__DisplayClass11.<FindTypeMember>b__d(MemberInfo prop) at System.Linq.Enumerable.FirstOrDefault(IEnumerable`1 source, Func`2 predicate) at AutoMapper.TypeMapFactory.FindTypeMember(IEnumerable`1 modelProperties, IEnumerable`1 getMethods, String nameToSearch, IMappingOptions mappingOptions) at AutoMapper.TypeMapFactory.MapDestinationPropertyToSource(LinkedList`1 resolvers, TypeInfo sourceType, String nameToSearch, IMappingOptions mappingOptions) at AutoMapper.TypeMapFactory.CreateTypeMap(Type sourceType, Type destinationType, IMappingOptions options) at AutoMapper.ConfigurationStore.CreateTypeMap(Type source, Type destination, String profileName)
at AutoMapper.ConfigurationStore.CreateMap(String profileName)
at WindsorAutoMapper.Mapper`2..ctor(IConfiguration configuration, IMappingEngine mappingEngine) in Mapper.cs: line 23 <projectfile:20C263C0-C7BB-4EC9-8922-93F433E8A561%2Ff%3AMapper.cs%3F23%3F1> at WindsorAutoMapper.DummyMapper..ctor(IConfiguration configuration, IMappingEngine mappingEngine) in DummyMapper.cs: line 7 <projectfile:20C263C0-C7BB-4EC9-8922-93F433E8A561%2Ff%3ADummyMapper.cs%3F7%3F1>

Is this a bug in Castle Windsor? Or am I doing something wrong in my AutoMapper registration?

Regards,

Jochen Jonckheere
--
You received this message because you are subscribed to the Google Groups "Castle Project Users" group. To view this discussion on the web visit https://groups.google.com/d/msg/castle-project-users/-/GqCYuXt4pWsJ. 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.

--
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.

Reply via email to