This is a 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 projects:
1. 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].
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.