Is everything okay in the container if you drop a debugger breakpoint after you install everything? There are some visualizers that will point out any configuration errors. You might be missing some dependency lower down the chain that's preventing your service from being initialized.
Also, you probably don't want your repositories to be singletons because that will make session management tough, although that depends on exactly how the repositories are implemented. You'd probably want to use the PerWebRequest lifestyle there. I realize you may just be trying to get it working before moving on but I thought I'd point it out. On Friday, September 16, 2011 at 9:04 PM, Gitted wrote: > This is a asp.net (http://asp.net) mvc3 application. > > My registrations currently (based on the mvc tutorial on the castle > site): > > private static IWindsorContainer _container = new WindsorContainer(); > private static void BootstrapContainer() > { > _container = new WindsorContainer() > .Install(FromAssembly.This()); > var controllerFactory = new > WindsorControllerFactory(_container.Kernel); > > ControllerBuilder.Current.SetControllerFactory(controllerFactory); > } > > Now I want to add a IUserService constructor parameter to my > HomeController: > > > public HomeController(IUserService userService) > > > My services look like: > > public class UserService : IUserService > { > private IUserRepository _repository; > > public UserService(IUserRepository repository) > { > this._repository = repository; > } > > .. > .. > } > > > One thing to note is that I have different vs.net (http://vs.net) projects: > > 1. asp.net (http://asp.net) mvc web > 2. services > 3. nhibernate (mappings and repositories) > 4. entities > 5. interfaces > > When I try and load my website, I get an error: > > No parameterless constructor defined for this object. > > If I remove the IUserService from the HomeController's constructor > (and any references to IUserService) the index action renders just > fine, so it seems to be this wiring up that isn't working. > > I have the following installers: > NHibernateInstaller > WindsorControllerFactory > > ControllersInstaller: > public void Install(IWindsorContainer container, IConfigurationStore > store) > { > container.Register(AllTypes.FromThisAssembly() > .BasedOn<IController>() > .If(Component.IsInSameNamespaceAs<HomeController>()) > .If(t => > t.Name.EndsWith("Controller")) > .Configure(c => > c.LifeStyle.Transient)); > } > > RepositoryInstaller: > public void Install(IWindsorContainer container, IConfigurationStore > store) > { > container.Register( > AllTypes.FromAssemblyContaining<UserRepository>() > .Where(type => type.Name.EndsWith("Repository")) > .WithService.DefaultInterface() > //.Configure(c => c.LifeStyle.Singleton) > ); > } > > ServicesInstaller: > public void Install(IWindsorContainer container, IConfigurationStore > store) > { > container.Register( > AllTypes.FromAssemblyContaining<UserService>() > .Where(type => type.Name.EndsWith("Service")) > .WithService.DefaultInterface() > .Configure(c => c.LifeStyle.Singleton)); > } > > > What seems to be wrong? > > -- > 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] > (mailto:[email protected]). > To unsubscribe from this group, send email to > [email protected] > (mailto:[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.
