wayfarer
wayfarer

Reputation: 790

business layer code outside of Controllers folder gives compilation error

I've read in other posts that you can put the business logic in a VS2013 MVC project "anywhere", which I take to mean "possibly outside the Controllers folder".

However, when I create an App_Code folder in my project, and put business logic classes in it, (with the build property set to Compile, not Content) I get a compilation error, on the following, and the code editor intellisense won't recognize the the .Caching in the following:

using System.Runtime.Caching;

If I move the class back into a subfolder of Controllers, no problem, the .Caching appears in intellisense and no compilation error occurs.

Any explanations of why this might be so, and how I might adjust my project to allow business logic classes to operate correctly outside the Controllers folder, would be appreciated.

Upvotes: 0

Views: 174

Answers (3)

Leo
Leo

Reputation: 14850

First off, there's no such ting as App_Code folder for MVC.

Why?

Well, the App_Code concept is meant to work with Website Projects, however, MVC are Web Application Projects which is a framework or implementation of a pattern to work closer to the HTTP protocol and web requests and separate concerns into presentation (views), request handlers (controllers) and models. So, don't expect it to work with App_Code

Suggestion

Create/Add a Class Library project in the same VS Solution where you can keep all your business logic and then reference this project in your MVC app

Upvotes: 1

Brendan Green
Brendan Green

Reputation: 11954

The App_Code folder contains code that is compiled at runtime.

See the following reference: http://msdn.microsoft.com/en-us/library/t990ks23.aspx

If you have business logic, it's probably best to put it into an external (from the webiste) library to increase reuse and enable better compartmentalization.

Upvotes: 1

Jian Huang
Jian Huang

Reputation: 1185

Add a business layer class library project to your solution, and then add reference to this business layer class library project to your MVC project.

Upvotes: 1

Related Questions