Solution structure for ASP.NET 5 - asp.net

We are a small dev team that has inherited a decent sized ASP.NET MVC project started a few years ago with ASP.NET 4. We are looking to migrate to ASP.NET 5 at some point. Currently the solution has 3 projects - Data, Services, Web. The data project uses the Entity Framework. The Web project previously was just MVC but now houses a Web API where we have a couple hundred RESTful API calls and an AngularJS frontend.
It looks like the ASP.NET 5 default solutions for web applications uses a new structure with the web project containing wwwroot and other things. Would you recommend having multiple projects or should we keep the data and services in the main project? I'm leaning towards the single project approach, but I'm unsure what the best long term structure would be. Thanks!

One solution, many projects. The point is to separate reusable components of your project. In fact, I'd add one more project to the ones you listed in your question. Models.
Let's say you decide to add another application to your solution. It might be a Xamarin Forms app, a WPF app, console app, Windows service, whatever. If your Models and Data Layer are each in their own class library, you can reuse them without needing to duplicate code. If you had put your models and data layer in your Web API project, you wouldn't be able to reuse it in your new app easily.
The only thing that I wouldn't necessarily (thought I still might) combine is the Web API app and the Angular app. Those two are probably so intricate that it makes sense to keep them in one project.

Related

Asp.Net core Web API calling

I am new in Asp.net Core and trying to clear my concept on web api. I have basic knowledge on web api. I can do CRUD operation using web api by running that web api project and calling it in other web application project at a time.
My problem is,
I add an web api in a web application project named "Api_BusinessUnit".
How can I call this web api in a controller named "BusinessUnitController" shown in below image. My confusion is, Both are in a same project, I can run one project at a time. So how can I use this web api in "BusinessUnitController" ?
Thanks in advance.
Why do you want to have one Web API call another in the same project? If you need to communicate between parts of your project, you can do so directly without having to over the web, which will be much better from a performance perspective and will be more reliable as well.
That said, looking at your image, I think you have two separate web projects in the same solution which isn't the same thing at all (you may wish to update your question if this is the case). To have one project communicate with the other project, you should determine the URL of the destination project and call it as you are doing. You also will need to ensure both projects are running, of course. You can launch multiple projects at once when you hit F5/ctrl+F5 as shown here:
http://ardalis.com/how-to-start-multiple-projects-in-visual-studio
For me, I am a Scott Allen fan and he explains the project structure for the particular structure you are trying to create here.
https://odetocode.com/blogs/scott/archive/2013/07/01/on-the-coexistence-of-asp-net-mvc-and-webapi.aspx
However, I am a fan of best practices and SoC, so the proper way, IMHO, is to have one solution with multiple projects and either keep the entire solution in version control, or have the project solutions separate, build and deploy to a directory will all of them for testing.
Then the key factor to running MVC and WebApi as different projects in the same solution, besides making sure that Microsoft.AspNet.WebApi.Core is installed, is that the start up project is the MVC and the WebApi references that MVC. Then you're off to the races.

How to use ASP.NET MVC Master Pages Solution in Individual ASP.NET MVC Projects

We have an ASP.NET MVC project to serve as a master portal. The portal has links to controllers/views in other ASP.NET MVC projects. When the link is clicked, we want to a view from a different MVC project is loaded into the body of the master portal.
We know ASP.NET MVC provides Area within the MVC project to organize related functionality into a group functions. But instead everything in a project, we prefer to have related functionality into a separate project but they share the same master portal.
Is it doable within ASP.NET MVC and how?
Depend on what is your exact requirement,
If you want to share only data between projects expose controller
actions and share the data by means of JSON.
Sharing UI between project may not come handy in the long run.
Before anything, have a look at this article
Always there is way to do everything in programming, but consider performance and best practices to keep your application long living.

Migrate Existing Web Form Application to ASP.Net MVC Single Page Application

I have an application which is built in ASP.Net WebForms and Silverlight.
There is another WCF services application which is accessed by silverlight part of my application.
Now I have to Re create the whole application in an MVC Single Page Application(SPA) and of course the WCF one because now I would need Web API for that.
An initial solution comes into mind is to add a web api project into wcf services application and start creating web methods there and call wcf methods from there if that functionality was already there.
And for webform start a new spa with mvc project from scratch and use durandal or any other spa client framework(hell of coding).
Any useful solution/advise? as I am looking for simplicity.
I searched around and found some questions but really did not helped as they are about merging with existing apps.
Note: application is a large application with a lot of functionalities
You have to decide how confident your team is with client side frameworks. Development of Single page applications may not be easy in the beginning, but you will get used to it very quickly. It's very important to give your team the right training.
In my opinion, Durandal is the simpliest, most elegant and complete framework to build enterprise level SPAs. It is important to know how knockout, requre and durandal's router and composition work. For data centric application I would use breezejs to manipulate and cache data on the client side and request it from the server side. Breeze works best with Entity Framework on the server side, but it's not necessary. If you can use Entity Framework, it will simplify your development, because it can generate metadata of your database structure for breeze. If Entity Framework is not an option, metadata can be written by hand.
I would make server side as thin as possible. Serving data from your database using web api with ORM of your choice and some cshtml pages.
Durandal Get Started is a good place to start.
Durandal Auth is a very good template for enterprise level SPA. It may not suit you completely, but you can use it as a guidance to build different modules of your application.
Breeze samples I suggest you consider using breeze. There are good courses available on pluralsight.
Knockoutjs has good training on data-binding.

Possible to create ASP.NET MVC web site (vs web application)

I'm looking at the differences between a Web Site and a Web Application on MSDN, and am drawn to the features of a Web Site because I am tasked with devising an architecture in which customers can heavily customize the application we deliver. It seems this feature of web sites would be useful:
You want to be able to update individual files in production by just
copying new versions to the production server, or by editing the files
directly on the production server.
However, I'm also drawn to the MVC architecture because it has built in features for minifying scripts that are delivered to the client. I also kind of like the idea of breaking up the architecture into clean pieces since this is a very large data model we have.
But from what I can tell, these sets of features appear to be mutually exclusive. Is that true? I can't readily figure out how to create an MVC application in which custom views could be dropped in as pure source files, and be able to run, nor can I figure out how to take advantage of any MVC framework when creating a "Web Site" project. Am I missing something or do I have to pick my poison?
Take a look at ASP.NET templates in VS2013. You can create an app with both MVC and WebForms. This will probably give you a good combination of what you need. By default, view files are not compiled, so you'll always be able to publish new files without doing a full push if you want. In fact, VS2012 even allows you to publish select files or folders.
The choice between web site and web app to be is very simple. If you are creating a mostly static app, choose "web site". If you are creating an app that has even a decent amount of dynamic capabilities, choose "web app". Web Sites are not really designed to be dynamic, so the more dynamic you do in that setting, the more of a headache it will be to properly maintain it as the architecture just isn't where it would need to be.
What I would suggest is to spin both of them up and try out some scenarios that you are interested and see what works and what doesn't. Really think about how users will actually want to customize the app. Will they want to copy and paste files to production or would they rather request features and have them built properly? Or maybe they want to work with a workflow instead?
So make realistic business requirements, prototype and then decide. But based on what I'm hearing you want a WebApp and probably one that does MVC and WebForms.
Now everything ONE ASP.Net. You will be creating a WebForm, MVC, Webpages using ASP.Net platform.
Check this video about new features in VS 2013
Not sure you can create website in ASP.Net 4.5.
From my experience, I would go with WebApplication based project, where managing namespace and other stuffs are easy. In website its hard to get the standard name for the classes(randome) generated.
Go with MVC web application.

What points to keep in mind while coding a MVC 3 project for easy upgrade to MVC 4?

We are starting a new project, but we don't want to use beta software. At the same time, we can not wait for MVC 4 release.
Will the application you are developing support multiple devices (mobile, tablet, and PC)? If it will support multiple devices then there are some considerations on how you structure your project and naming conventions used to switch to device specific controllers and views. Checkout this tutorial for an explanation of the changes. Also if your application will have some REST web services or API's then you will want to look at the ASP.NET Web API, which is part of MVC 4.
Moving from MVC3 to MVC4 is pretty easy. Here are the specific notes from Microsoft: http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253806
I just upgraded a big MVC3 application to MVC4. We did the option of creating a new project, 10 minutes total and everything from MVC3 worked fine.
What you miss out on is developing the new features from the start (since it's a new project). But given your constraint this should be acceptable.
Also to note: MVC4 comes with a "go-live" license (http://weblogs.asp.net/scottgu/archive/2012/02/19/asp-net-mvc-4-beta.aspx) so you could use it in production today.

Resources