Models in ASP.NET Core Web API - asp.net-core

Why are models not in a separate Model folder in the api template? The original template comes with WeatherForecast.cs as a separate file just by itself.
Are we not supposed to have a folder for models?

In this template you actually get minimal settings for ASP.NET project as program.cs and startup.cs with minimum configuration.
Then you choose how your folders will be located, depending on what you are going to do. If you want to make a couple of controllers with couple of methods, and you are not going to expand the functionality, you can write all the functionality of your program there and create two folders: controllers and models. In the case where you need to build a large application with a lot of logic, you need to use common web application architectures.
You can read this article and find a right direction for searching, but it is more than just "separate file and folders", this is a very big topic for thought.

Related

Area as a separate project in ASP.Net MVC

I need to develop a web application of hotel. Some hotels have lodge system as well. How can I make lodge as pluggable module. I went through many links and found that area might be a good solution but I couldn't find out the best solution. The foremost thing I need to check whether the lodge module is present or not. If lodge is present then in main project I need to add a button to go to lodge system. How is that possible? If so then please share me a tutorial or a link.
Look at MVC Razor Precompiled Views to keep views and code in another project. Use dependency injection to share common infrastructure code.
This github repo should contain what you need https://github.com/RazorGenerator/RazorGenerator
Potentially you can make Lodge a night package and share it between projects that way. Alternatively look at making code base multi tenated and make parts of application customizable per customer

Modules in Zend Framework 2 (ZF2)

Let's say that I'm building a social networking web site. Should I put the whole web site under SocialNetworking module should almost each page have its own module like ProfileModule, MessagingModule, and GalleryModule?
Or it is somethink differen like AvatarModule, UserToUserConnectionModule like FriendshipModule, PrivacyModule?
Modules are not containers of different "pages" of a website.
A module can literally be anything, but in most cases it provides "features" (services, listeners, events, classes, generally logic) for your application.
Don't separate modules thinking at them as separate URLs in your web application: instead, think of them about containers of reusable code.
As a rule of thumb, a Zend Framework 2 Module can be separated from the other functionality on your application if it provides logic that you may want to reuse in another project.
As you can see, it's all about producing reusable and decoupled portions of your application.
Just to add something to the good answer of #Ocramius, the examples you've given can ALL be modules.
You can have a "BlogModule". This module would handle BlogPosts. Then you could have an additional "CategoriesModule" that adds the option to give each BlogPost a Category. Then you could write another Module "MediaModule" that adds the functionality to attach Media to your BlogPosts

asp.net mvc 4 localization resource path too long

I've created a class library in which I store my resource files for my asp.net mvc4 localization. I've been following the same folder structure as my Views.
I'm ending up having to reference strings such as:
#Resource.QuoteArea.Quote.Auto.DriverInfo
That is very long and tedious to type. Plus it makes my Views hard to read. Is there a better (neater) way for doing localization in mvc 4 ? Perhaps using a third-party library ? I already use mvccontrib for my model localization, so that's sorted. However for non-model related things, I'm facing the aforementioned issue.
You can change the resource namespace in the resource properties, to make it shorter. This blog post was very helpful for me, and will be for you to.
http://adamyan.blogspot.co.uk/2010/02/aspnet-mvc-2-localization-complete.html

Writting My lightweight MVC framework

I have planned to write my own light weight MVC for PHP, that will be used as base for my sites I develop. I have no problem with PHP, OOP, et al. I have trouble on how to actually load Models In controllers and use them amd loading Controller values into Views. In short, I don't know how M-V-C interact behind the scenes.
Any tutorial (concentrating on that) or any contribution is welcomed!
Thanks!
ASP.NET MVC is open source: http://aspnet.codeplex.com/releases/view/58781
Edit: consider this: I believe you are trying to reinvent the wheel, thinking that those MVC framework out there are heavy and packed with uncessary features (acording to your double use of the word lightweigth). In my experience, I always ended up coding those extra "features" because a framework is required to evolve. Loading models In controllers, using them and loading controller values into views is just the begining. If you want to get started eventually, it would be a better investment to write some helper classes and methods: a popular pattern in the MVC world. Unless you are writing a MVC framework from scratch for fun and I am totally wrong (you said you needed a base to use for your sites ).
Best of luck!
Codeigniter is an open source MVC framework of php.
http://codeigniter.com/user_guide/overview/appflow.html
The major in MVC is first of all your controller class initiated and then calls view.
After google and check how other MVC works I decided to take this route. I redirect all my requests with .htaccess to index.php. Then there I define base paths. After all the definitions I include the core.php which in turn includes all core files to my mvc framework. Then in the same file I create Instances of Registry and router and the game starts from here!
Internals are a bit complex now but that is what I ended with!

Serializing versioned workflows using Microsoft WF

I have a simple business workflow with the following conditions
Users need to change the workflow itself using a desinger
The workflow is a long rinning workflow, so it will be serialized
Is there a way to automate the task of versioning different workflow assemblies?
The versioning of different workflow assemblies is not a trivial task and has a lot of complications. Here you can find a series of posts that deal exactly with this.
You can rehost the WF designer in your own application to let the end users change workflows. As you are hosting the designer you pretty much control what they can do. For example you can prevent them from removing or disabling activities and only allow them to add specific new activities in predefined area's of the workflow. The best approach is to save these workflows as XOML files and start them as such. This does mean you cannot add code to the workflow itself but you are free to define your workflow base class derived from SequentialWorkflowActivity (or the state equivalent) and use that as the workflow base class. This allows you to add code and properties. For example you can still add a CodeActivity but you need to link to code in the base class.
Workflow serialization, or dehydration as it is called, is used with running workflows to persist them to disk. This uses standard .NET binary serialization and can be a but tricky due to the long running nature of workflows. But no big deal once you know what to look for. See http://msmvps.com/blogs/theproblemsolver/archive/2008/09/10/versioning-long-running-workfows.aspx for the start of a series of blog posts.
Not sure if you need it but there is also the capability to change already executing workflows. This uses the WorkflowChanges object. See here http://wiki.windowsworkflowfoundation.eu/default.aspx/WF/RuntimeModificationOfWorkflows.html for more details.
Here is another article on workflow versioning:
http://www.adefwebserver.com/DotNetNukeHELP/Workflow/VacationRequest3.htm
Basically you can version workflows that use assemblies if:
Any assembly used with workflows
must be strong named.
If a assembly
uses an interface it also must be strong
named and placed in a separate
assembly.
An entry in the web.config
can instruct asp.net where to find
the proper assembly.