Controllers in a different project - ControllerBuilder

Jun 22, 2010 at 9:16 PM

I have placed my controllers in a different project.

Usualy I had to create a ControllerFactory and pass it to ControllerBuilder ( etc.: ControllerBuilder.Current.SetControllerFactory(typeof(NinjectControllerFactory)); )

I would like to ask, how to do this using mvc turbine ?

Help me please :)


Jun 22, 2010 at 9:19 PM
Turbine eliminates all of that work. All you need is to reference the assembly to your application and Turbine will find and add the controllers to the underlying IoC for you.
Jun 23, 2010 at 7:10 AM
I have another problem. In turbine documentation I found the following line of code protected override void AutoComponentSetup(IServiceLocator locator) { //Remove this if you want to skip all other previous registrations base.AutoComponentSetup(locator); AutoRegistration<IMyCustomInterface>((loc, type) => loc.Register<IMyCustomInterface>(type)); } ... but when I reflect turbine assemblies I didin't find any method named AutoComponentSetup. Is the documentation up to date ?
Jun 23, 2010 at 4:36 PM
Sorry to say but the documentation is out date. We're currently working on updating the documentation and making start up guides and tutorials more readily available.
Jun 24, 2010 at 10:35 AM
Could you tell me how to deal with missing AutoComponentSetup method ?
Jun 24, 2010 at 11:25 AM
It might be easier to help if we know what you are trying to do with the method. What do you need the application to do?
Jun 24, 2010 at 7:11 PM
Edited Jun 24, 2010 at 7:18 PM
I'v listed some of my code below: , global.asax ... public partial class MvcApplication : TurbineApplication { static MvcApplication() { IKernel kernel = new StandardKernel(new AppModule()); ServiceLocatorManager.SetLocatorProvider(() => new NinjectServiceLocator(kernel)); } ... } AppModule.cs public class AppModule : NinjectModule { private static DocumentStore documentStore; static AppModule() { documentStore = DocumentStoreFactory.GetDocumentStoreInstance(DocumentStoreFactory.PRD_URL); } public override void Load() { Bind<IDocumentSession>().ToConstant(documentStore.OpenSession()).InRequestScope(); Bind<IPostRepository>().To<PostRepository>().InRequestScope(); Bind<PostViewModel>().ToSelf().InRequestScope(); Bind<HomeController>().ToSelf().InRequestScope(); Bind<PostController>().ToSelf().InRequestScope(); } } when I lanch my app a get "the resource cannot be found." exception
Jun 25, 2010 at 12:15 PM
Edited Jun 25, 2010 at 12:16 PM
I'm not sure if this is what you want to do, but it appears that you need to use the Ninject controller factory instead of the Turbine controller factory. It looks like some of the methods on your IoC registration, like InRequestScope, are tied to Ninject-specific behavior. This is an assumption, since I haven't done this with Ninject, but I bet you could replace the Turbine controller factory with the Ninject controller factory and everything will still work, since all Turbine does is run the controller instantiation through your IoC container. You can do the replacing in the constructor of your MVC application, like so:

public MvcApplication()
var locator = new NinjectServiceLocator();

locator.Register<IControllerFactory>(new NinjectControllerFactory());


If you need to do some specific Ninject registration, you can always pull the Ninject container out of the NinjectServiceLocator, then use Ninject's registration and module-loading capabilities.

Again, I'm not sure this is what you want, does that help?