Custom components and ASP.NET MVC - asp.net

I was curious how in the typical ASP.NET MVC mentality one could build a platform that others could develop plugins for. I mean, how would those plugins look like?
Like exiting user controls for WebForms, encapsulating all layers in themselves, or three different files representing the model the view and the controller. I should develop the core of a CMS, that I'd like others to build plugins for later on. Which mentality is better for that, classic Web Forms or ASP.NET MVC?
I need developers to be able to separately build components for that. Is it possible to encapsulate the MVC directory structure in a component DLL file and then when I reference the DLL file, to be able to directly access the component's model, view, or controller as part of the general MVC structure?

The most promising component techniques have come from the guys over at lostechies.com and Mvccontrib in the form of Portable Areas. Portable Areas allows an entire MVC app to be appended onto an existing application. So its not just a UI component but also provides all the work flow and screen integration as well.
Open Forum does something like this as well. I don't know how, but it is very plug and play.
For straight up plugin architecture there is an interesting screencast and source code for Rob Connery's link text. He takes advantage of the App-Code directory to slide new plugins into place without having to edit the main site.

Related

Should i create an Empty Web Application or Web API Web Application template? - VB.net

I wanted to build a VB.net web application using MS Visual Studio 2015. Someone suggested me to create a Web API instead of MVC project if i'm also planning to create a mobile app later on. I may use angularjs in my project so controllers will surely be used, so what should i choose when creating the project in the first place?
Because when i created a web project: File=>New Project=>ASP.net Web Application=>Empty..there are no folders for Controllers, Model, etc. Do i have to create a Controller folder on my own?
Or should i do this: File=>New Project=>ASP.net Web Application=>Web API..? sorry if its a silly question. its just that i'm afraid that if i chose the wrong project now, it'll affect the development later on.
Answer to your question mainly depends on your choice and needs,
for example
In Case of an empty project as name defines you will have nothing else web.config.
Benefits of it:
here you can define, design your own structure. you can either make
it simple 3 tier or you can make it WEBAPI application. it's all up
to you.
however in the case of choosing Webapi template you will have a prebuilt structure which can help you out for initial understanding
https://docs.asp.net/en/latest/tutorials/first-web-api.html
benefits of it
You will get predefine template and structure.
you can utilize of webapi's which further isolate you backend logic from the frontend.
as you are also planning to create the mobile app. and using front end as angular, so in that case, webapi may come handy.
as the whole world is moving towards webapi, so i will recommend you to use it. please refer https://blogs.msdn.microsoft.com/martinkearn/2015/01/05/introduction-to-rest-and-net-web-api/
so down the line it all depend on you if you want to build you application for the stretch and take full control of it regarding structuring backend etc.. then go with empty else go with Microsoft pre-define template
Thanks,
Ajay Kotnala

ASP.NET web api with angular project structure

First time asp.net webAPI + angular project. From many examples I've seen online I've found there are basically two ways for handling the views.
The first (which I have seen in many tutorials and courses) - use APIcontrollers only, so that the view are generated by angular. That means my project structure would have a folder 'app' and it will contain the html files (probably inside a 'view' folder). The routing will be done using angular routes. I will only have APIControllers in the project (without the regular Controller object).
Example project: https://github.com/DanWahlin/CustomerManagerStandard
The second - using Controllers to generate the views, using Razor (cshtml files), and angular incorporated into those (i.e ng-click inside the cshtml). There's no special 'app' folder for angular etc.
example project : https://github.com/Wintellect/Angular-MVC-Cookbook/tree/master/CRUDOperations
So, I'm wondering what are the pros and cons for each method, and when shall I use which one. Examples projects would be great as well.
I can only assume that the first method is more modular and differentiate server and client. However, using it means I'm loosing razor (Do I even need it?)
Thanks!
I actually had to make this decision a few months back myself.
This comes down to what you feel is more comfortable. I chose to do angular and WebAPI controls only. It makes me think in terms of true separation of concerns just easier, angular is your presentation layer and webapi is your services. This also gives you the freedom to do the compression/formatting of the actual html pages(instead of the cshtml pages which you really have no control over).
One more pro for WebAPI only is scalability, you would really only need one webserver for the webpages but you can scale out your WebAPI, this will allow you WebAPI to be your api as well as your clients as well.
Razor is just a view engine and in my experience angular does a good job of templating and directives to bear the cost of losing razor. You'll probably end up writing pure HTML in your razor files anyways once you get a hang of directives which means you'll have more of an issue adding a new view. Who wants to create a new controller, new action and a new view, and then have to do that in angular. It just ends up being easier and less complex to let server serve the html files, and let angular do all your routing and logic for you.
I believe too that the html files get cached too so you will see less round trips as you navigate page to page in angular.
As a person who works at a Microsoft shop and loves AngularJS for nearly all my front-end, the sooner you get away from mixing Razor and AngularJS, the better, especially if you are going for a SPA.
The only time I would recommend using Razor at all would be to generate the landing page (and possibly login page/admin area). It does give a nice way to provide authentication to access the app and then use Web Api Authorization attributes to do the rest of the authentication.

ASP.NET MVC 5 EF6 Structure

after thinking a lot about this we are going to give a try to ASP.NET MVC to upgrade a complex Web Forms project we have. Since we are new in MVC we have a lot of doubts.
Our project has an administration panel or backend with more than 70 pages and then a public site where we show all the information.
1) We are going to use MVC 5 and EF6 with database first. We love the way we can create all the entities without writting a single line and also how can we update the model when we change the database.
We have seen how you can create the CRUD operations with the scaffolding feature. This way also we save a lot of time, but is this the best way to do it?
2) At web forms we had different layers and then, in the presentation layer we have an "admin" folder where the backend pages are. The public pages are at the root folder.
How do you manage this in MVC? Since MVC uses VIEWS how can we separate both parts? Also, different parts use same Models, but what about controllers?
3) Is it storing the Models and Controllers in their folders the best structure? We used to separate the project in different layers, but that was for Web Forms, we don't know which is the best approach in MVC, What do you think?
If you separate in different projects, could you show us an example?
4) Also we used Telerik ASP.NET Rad Controls for Web Forms. Those controles are great for Web Forms and we also have the license for MVC, but are those good to use in MVC? Are necessary?
We have a lot of grids where we have to make some operations, show images, have buttons, upload images...
Are there any other options?
Thanks for helping. We are new in MVC but we hope we can learn fast because it seems amazing what you can do.
1) We are going to use MVC 5 and EF6 with database first. We love the
way we can create all the entities without writting a single line and
also how can we update the model when we change the database.
We have seen how you can create the CRUD operations with the
scaffolding feature. This way also we save a lot of time, but is this
the best way to do it?
You do not want to use scaffolding feature. As you said in other question that your have over 200 pages of Web Form. If so, you want to split the application into multiple layers with loosely coupled.
2) At web forms we had different layers and then, in the presentation
layer we have an "admin" folder where the backend pages are. The
public pages are at the root folder. How do you manage this in MVC?
Since MVC uses VIEWS how can we separate both parts? Also, different
parts use same Models, but what about controllers?
You can use Area.
3) Is it storing the Models and Controllers in their folders the best
structure? We used to separate the project in different layers, but
that was for Web Forms, we don't know which is the best approach in
MVC, What do you think? If you separate in different projects, could
you show us an example?
Look at open source projects such as NopCommerce, Orchard or Umbraco.
4) Also we used Telerik ASP.NET Rad Controls for Web Forms. Those
controles are great for Web Forms and we also have the license for
MVC, but are those good to use in MVC? Are necessary? We have a lot of
grids where we have to make some operations, show images, have
buttons, upload images... Are there any other options?
Telerik has Kendo UI. If you have DevCraft Ultimate, you can use Kendo UI
Professional which has MVC wrapper for Kendo UI. Basically, wrapper let you use HTML Helpers instead of hand coding JavaScripts.

Implement a multiple web project structure in asp.net webforms

I'm working in a web application that has several areas of bussiness work. With time it's size has became a problem to develop on and to maintain.
I would like to break the web project into several sub-projects or libraries depending on a main root web project that has the common files to share (Masterpages, Resources, Css, etc...)
Ideally I would like to have some kind of injection that allows me to optionally publish that "components" or simply publish a customized variation, although it's configuration depended on after deploy DB setup.
I searched all over the web, reading all the pages related to multiple projects, dependency injection and composite apps that I could find, 'till I soften my head, but couldn't find anything really useful.
Major part of the writings where a theoretical approaches or unit testing applications (well, you can't make your desired app, but you still can unit test something else)
Other approaches simply don't work in VS2010 .Net 4.0
Can someone address me on a COMPLETE solution or an example? Or simply lets discuss.
We say that the solution has the following structure, with module contents already separated into directories:
Solution
L_ Datalayer library project
L_ Bussiness logic /common utils library project
L_ Web project
L_ Controls
L_ Images
L_ Css....
L_ Warehouse
L_ Sales
Masterpages
...
Warehouse and Sales contains pages related to the "module"
Thanks,
I post my progress in the subject.
As per suggestion of Steven I experimented further more using MEF. Due to the lack of documentation, specially for webforms, that was a pain in*. So far I managed to implement MEF in my solution and sucessfully inserted a plugin project visible for the main app.
Then loads the available plugins, through an interface that has the plugin name, the default page url and its order, picks all this data and render a menu tab. That part it's easy.
Clicking on a menu element must redirect to the main page of the plugin, which will render several menus for its pages contained (from another export interface)
I finally got an aspx page embedded as a resource in the plugin project. Where I'm currently stuck.
¿Is there any way to render a page embedded as a resorce on a libray using MEF or I'm forced to also use a VirtualPathProvider? ¿Hows specifically the statement to redirect to that page? I've tried several ways but no-one works (MEF and VirtualPathProvider)
I looked at zillion of articles that talk about it but all them end doing control rendering, not page. So frustrating.
Though it is not an answer to your question, I am adding it as answer due to length of my suggestion.
I suggest you look into the approach NopCommerce is following where they have extended over .net with their own framework, which supports Plugins and extensions to existing solutions. Though I definitely know that nopcommerce is an ecommerce solution but if you study it, you can modify it according to your business needs or at least it can give you a heads on for what you should adopt while designing your solution. Hope it helps.

Modularized design question using asp.net

I am looking for an advice on the design decision. I want to create a reusable module(s) include aspx pages. Let’s say I have a huge project which has 10 different modules. When I built the modules all of the modules are built with its own business logic and data access layer. But the UI (.aspx/.ascx) is in one single project. I want to have UI also to be separated and put in the same project related to that module.
Here is the scenario, let’s say, I have created a news feed reader module for twitter, which has
NewsReaderBO – Business Layer (could be in web service)
NewsReaderDAL – Data access Layer
I want to create a NewsReaderUI project where the related UI is placed in such a way it should be easy to plug into other projects.
The advice I am looking for is how the main container project should be designed/organized/architected so that integration of these sub projects is easy.
Are there any references available for this scenario?
The challenge is, over my experience I have worked on various modules now it so happened that when I am creating a new site. I am copying the code from each one, whereby I end up having so many copies of the same thing.
Any advice on this?
Regards
Sai
If you are doing a webforms application you could put each module into it's own library. In the library you could put your code for the module and implement the UI for the module as a server control instead of apspx or ascx, and then use those in pages pages in your main project.

Resources