http://stackoverflow.com/questions/1746387/castle-windsor-problem-with-multiple-constructors/1747477
Krzysztof already registered the issue: http://support.castleproject.org/projects/IOC/issues/view/IOC-ISSUE-168 On Nov 17, 9:48 am, Jordan <[email protected]> wrote: > I am currently undertaking a conversion from to the use of Ninject to > the current release of Castle Windsor for a simple C# .NET > application. > > For the most part, the conversion has gone well and the implementation > of the containers has executed flawlessly. I am however having a small > issue with my repository objects. > > I have a user repository object that is coded in the following > fashion: > > public class UserRepository : IUserRepository { > public UserRepository(IObjectContext objectContext) { > // Check that the supplied arguments are valid. > Validate.Arguments.IsNotNull(objectContext, "objectContext"); > > // Initialize the local fields. > ObjectContext = objectContext; > } > > public UserRepository(IObjectContextFactory factory) > : this(factory.CreateObjectContext()) { > } > > // ----------------------------------------------- > // Insert methods and properties... > // ----------------------------------------------- > > } > > To correspond to this code, I have setup the following entries in my > application's configuration file: > > <castle> > <components> > <component id="objectContextFactory" lifestyle="custom" > > customLifestyleType="Common.Infrastructure.PerWebRequestLifestyleManager, > Common.Castle" > service="Project.DAL.Context.IObjectContextFactory, > Project.DAL.LINQ" > type="project.DAL.Context.ObjectContextFactory, > Project.DAL.LINQ"> > </component> > <component id="userRepository" lifestyle="custom" > > customLifestyleType="Common.Infrastructure.PerWebRequestLifestyleManager, > Common.Castle" > service="Project.BL.Repository.IUserRepository, > Project.BL" > type="Project.BL.Repository.UserRepository, > Project.BL.LINQ"> > <parameters> > <factory>${objectContextFactory}</factory> > </parameters> > </component> > </components> > </castle> > > To me, everything looks like it should. When I attempt to resolve an > instance of the IObjectContextFactory service, I retrieve an > ObjectContextFactory object. My problem comes in when I try and > resolve an instance of the IUserRepository service. I am treated to > the following delightful exception: > > Can't create component 'userRepository' as it has dependencies to be > satisfied. userRepository is waiting for the following dependencies: > > Services: > > - SandCastle.DAL.Context.IObjectContext which was not registered. > > When I switch the constructors around, this works just fine. My > impression of the way that Windsor works is that it will find the > constructor for which it can resolve the most parameters and us that > one. It doesn't seem to be doing that in my case. It has been posed > to me that this might just be a bug. -- 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=.
