Create Reusable ASP.NET MVC Project - c#

I have a couple of similiar ASP.NET MVC projects (solutions). These projects have several identical Controllers/Views and _Layout (MasterPage). I would like to distinguish these identical elements into separate reusable project. Is it possible to create such reusable project in ASP.NET MVC? And which techniques I have to use for it.
Thank you in advance.

You can try MvcContrib Portable Area http://mvccontrib.codeplex.com/
http://mvccontrib.codeplex.com/wikipage?title=Creating%20a%20Portable%20Area&referringTitle=Documentation

You can create template from your project http://haacked.com/archive/2011/06/06/creating-a-custom-asp-net-mvc-project-template.aspx
For parell develop, better approach maybe is to organise your projects like here: http://lostechies.com/jimmybogard/2009/12/09/organizing-asp-net-mvc-solutions/

Related

How to share a method in an ASP.NET core web app

I have a few utility methods I would like to access from various pages in my ASP.NET core web project. I assume there is a simple way to define the methods once and call from various pages without copying and pasting the utility methods into each page that uses them.
I see recommendations to add a WebAPI project to my solution, but that seems like overkill for a couple of methods.
Is there a simple way to share a method within a project I'm missing?

C#: Controllers in a re-usable library with the .net core framework

I've written all the classes and controllers for a web api to interact with a very large database (dozens of tables and controllers). I need to write a lot of small apps for specific tasks, as such, it would be idea if the controllers could also be a library file.
I've seen some old tutorials that suggest this is possible, but they no longer seem to work.
Could anyone please point me to somewhere that explains how this can be achieved; or, if there's a better best practices approach I should be taking.
Have all the object classes in their own library, and a working web app that interacts with the database. Want to extra the controllers into a library or include them in the existing object classes library.
By placing controllers in the library, do you mean having generic controllers so you can reuse them whenever you want for whatever model you need? Of so, you can check my library https://github.com/Ryukote/CoreGenerics which is also available on Nuget so you can add it to your project and use it as is.

Sharing controller and views between projects

I am trying to create a good infrastructure for my web framework I am developing I have the following structure so far
solitude.admin web project to keep the controlers and views in how do I create this one I created a class libary but see you cannot have a web.config there
solitude.core will contain all my utililties and models
solitude.framework will be the core and meat of the cms platform my quesiton is how does one create a class libary project for asp.net mvc 4.6 to allow controllers and views to be shared i addded razor to a dll but i dont think that is correct approach
solitude.mvc this will contain the front end of the site i tried the below changing project guids to allow the sharing but its not working
I also changed the project type guids as suggested on aricltes on so but no joy I am trying to mimic our other platforms already work to futher my understanding.
<ProjectGuid>{152C761A-DD2E-4C1F-AF89-DFB2547A3BCA}</ProjectGuid>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>solitude.admin</RootNamespace>
<AssemblyName>solitude.admin</AssemblyName>
<TargetFrameworkVersion>v4.6.2</TargetFrameworkVersion>
Another point is if I was two have two sep projects admin and web how would one tell it to go to admin if user types www.domain.com/admin but yet be two independent web projects?.
I totally understand you. I'm in the same situation. I suggest you take a look at AREAS. I'm still learning it, but for what I've googled, it is the proper way to share views and controllers between projects.
This is one good link
I see good the separation of concerns. But have some questions:
1.- Why not making "solitude.admin" another web app project?
2.- Why aren't you using the expected naming conventions? That is a lot of lowercases you got there.
3.- Why would you like/need to share Controllers? Basically, there must be a
return View();
inside them.
For views, you could create some components based on parameters (which mostly, it comes to print out some HTML). You already have Shared Views but for the same project.

structure for applying Identity on a multi-project solution

I've been working on a Web API solution that's separated on various projects, one of each is the API itself which contains the controllers and Views but all the Business Logic is done in all the other projects (being one of them responsible for all database iteration).
Now I want to apply Authentication using Identity which I wasn't familiar with but was able to understand a lot better thanks to this series of articles and so was able to get it to work on a test solution.
My question here is, how should I organize the different parts of the Identity implementation? Should I...
Make everything directly on the API project?
Create a separate project for all the Identity Implementation except for the controllers?
Use it some other way that you will suggest?
*If you suggest using different project, will I be able to pass the owin context between the projects? how?

Multiple MVC projects in a single solution

I have seen in NopCommerce project that there is a solution and there are multiple MVC projects within the solution.
I have some questions about it such as :
How is it possible to share a main layout, or use different layout on demand?
How is it possible to use Controllers/Models etc. in different MVC projects?
I would also like one main project and multiple sub MVC projects. How can this be done while sharing components?
Any ideas? pointers?
Note: Not interested in Areas.
Yes it is. See: asp.net mvc put controllers into a separate project
I've done this myself and was able to use the controllers in a plug-in type architecture.
As for the models, they are just normal classes. They can be used in any project for any reason. There is nothing special about them.

Categories