Try our conversational search powered by Generative AI!

Controllers in a separate project?

Vote:
 

Hi,

Iam trying to separate the controllers into a separate project. How do i modify the routing to handle this. 

I know in MVC you can add a namespace parameter to the routing, is that possible with EPiServers MapContentRoute?

Any ideas?

Thanks

Jesper

#86637
May 27, 2014 11:10
Vote:
 

You can add the controllers namespace to the MVC controller builder.

I usually add it an initialisation class of the project where I have my controllers.

[InitializableModule]
public class InitializeDependencies : IConfigurableModule
{


public void Initialize(InitializationEngine context)
{
ControllerBuilder.Current.DefaultNamespaces.Add("My.Class.Library.Namespace.Controllers");

}

public void Uninitialize(InitializationEngine context)
{
}

public void Preload(string[] parameters)
{
}

}



#86643
Edited, May 27, 2014 12:23
Vote:
 

Just curious what is reason for splitting it into separate assembly?

#86657
May 27, 2014 20:58
Vote:
 

I like to develop features that are "large enough" in separate modules, independent from the website. These features, more often than not, will have code that spreads accross all tiers of the implementation. 

An approach similar to add-ons development in EPiServer or modules in Orchard CMS.

This helps me re-use code between projects, helps in keeping the modules independent from each other, helps in testing single bits of functionality. 

#86672
May 28, 2014 10:54
Vote:
 

Ok clear. I would on the another hand prefer dumb controllers but clever services or other components that are located outside of web app. That makes possible to reuse the same business logic across multiple "endpoints" - mvc controller, webapi controller, wfc endpoint etc.

Btw, is "controller namespace" supported by "Goto Controller" from View markup in VS? Haven't tried.

#86674
May 28, 2014 11:04
Vote:
 

Same here, I prefer thin controllers that call rich services. By putting the full vertical slice in separate projects, I can ship them in independent modules.

You make a good point about the consumers but that can also be achieved using this development model.

I just tried the "Goto Controller" and it doesn't work. Tbh, I never use this function in VS. R# shortcuts all the way :)

#86676
May 28, 2014 11:10
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.