How to use Subsonic MVC Template? - asp.net-mvc

I started downloading the MVC Template, and created a new project using this template. I Compiled the application, and everything went fine so far.
My question is, where could i find the new sonic.exe file that generates the MVC DAL?
Is that the old sonic.exe?

So long as you're not using Express then the classes are created when you build your applicaion. Sometimes this doesn't work and you'll need to right click on the Models/Classes.tt and choose 'Run custom tool'.
You should then have a Classes.cs file nested under the Classes.tt file and the DAL objects are defined in there.

Related

following iterative and agile in asp.net MVC

ok, i know there are a lot of posts online that specify how to do iterations with MVC.
my question is slightly different. when i used to do iterations using WebForms, i was creating one thing only and finishing that one thing till the end which was including the deployment on production.
for example, i was creating a webpage and deploying it, then i create the second page and deploy it. so .dll files were added to my bin folder while the previous dlls remain untouched. at the other hand, when i was making a change latter on, there was this one file that needed to be replaced on production.
now here is the question, how can i acheive the same thing in mvc? beause it just doesn't deploy each page into an individual dll. each time that i add something i have to redeploy the application dll which is not really wise! i played around with deployment options in visual studio but no luck!
There is nothing preventing you from putting controllers and other code in separate assemblies and dropping them in an existing application. Like any ASP.NET based application an MVC application will automatically restart if you add or modify any file in the bin folder or modify web.config.
If you're using Razor you can use RazorGenerator to generate code for your views and compile them into the same assembly.
You may need to write some additional logic though to get routes, model binders etc. wired up correctly.
For a more structures approach to compose the application of separate modules, you may want to look into portable areas. This is an extension to ASP.NET MVC that allows you to package the entire module (including views, css, js etc.) into a single assembly.
First thing, you have to work on the title of the post, it does not match the content of the post.
In asp.net mvc u can choose to deploy only what changed. I.e. If you only changed the .cshtml file, then you can just replace it with the file in production. However if you change any controller class (C#/Vb code), then you will have to upload the web project dll file too so that this new changes are available in the production env

Entity Framework + MVC 4 + Knockout.js AddView templates?

I've been messing around with knockout.js a little bit lately and it seems like it has a lot of promise. However, I can't seem to find any good Code Templates (aka t4 templates or .tt files) for it.
My GUESS is that the only changes that we would need would be on the view side, not the controller side, but I'd be up for looking at new controller templates too.
Where I am right now:
Create a new MVC 4 project
Using NuGet, install entity framework 5, jquery, jquery ui, and knockout
Create a .edmx model by reverse engineering your existing database with Entity Framework
Drag C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates from Explorer into the root of your project
Delete CodeTemplates\AddController
Highlight all of the items in CodeTemplates\AddView\CSHTML and blank out the text in "Custom Tool" in properties to keep them from
building
Start screwing around with Create.tt and Edit.tt to add in knockout code.
Goal Expected Input: Right Click > Add Controller ... > MVC Controller using EF
Goal Expected Result: Controller & View created using EF with knockout code already in place.
If you use something similar to knockout that you like more, I'd love to hear about it!
Also, is it necessary to use addons like MVCScaffolding? It seems like you could just customize the existing templates and get the same results.
Thanks for your time!
I would go the MVCScaffolding route. You could create your own custom scaffolding script whenever you wished to add a controller, that is, as long as you can stomach PowerShell.

Are shared views still around in MVC 4 RC?

I'm brand new to MVC and I was trying to work my way through the music store tutorial:
http://www.asp.net/mvc/tutorials/mvc-music-store/mvc-music-store-part-3
I could tell right away that things looked slightly different in MVC 4 RC but one big thing I'm hitting is I don't see any Shared View being created when I add a Home View. In fact I don't see a _Layout* file anywhere within the project.
So my question is, has the shared view thing been replaced by some other mechanism or do I need to do something else to add this explicitly?
Thanks,
JT
From http://blogs.msdn.com/b/jasonz/archive/2012/05/31/announcing-the-release-candidate-rc-of-visual-studio-2012-and-net-framework-4-5.aspx:
If you’re doing web development, you’ll notice a handful of updates in
the RC. First off, we’ve updated some of the project templates. We
made the MVC4 Empty template truly empty, and renamed the original
empty template to now be called the “Basic” template. We also improved
the performance of the New Project creation time.
Essentially all of the initial templates have been cut down a lot. The Empty project doesn't come with a HomeController either - you can add anything you need back.
Apparently this is tied to how you start the project. If you select Internet Application when you create a new MVC project it will build these files for you but if you select Empty you have to create them manually.

Code generation: Custom controller templates

To start off, I'm using Asp.Net MVC 4, and I've modified my solution to contain the CodeTemplates folder by following this tutorial. (I think my issue might be MVC related?)
I've replaced the code in the Ajax grid template with a with my own JQgrid-template, which was fine for getting my project started. But I'm having trouble creating completely new controller templates (well the having them show up in the create new controller menu)
any ideas?
Update
I've taken a few stabs at using the scaffolding feature, but it's not exactly what i had in mind (although it does work like expected. I watched a video by steve sanderson on the topic that was quite informative), any way to get my custom views/controllers inside the add controller gui?
As far as my understanding of your problem goes, you cannot manage two controllers within one .ps1 file, which corresponds to your "AddController" directory.
You have to use the Package Manager and issue a command like
Scaffold CustomScaffolder <choose-name>
This will generate another subfolder below CodeTemplates with the name . From there, you open and edit t4 files like you did with your existing one.
More info here

What does WebActivator do?

This code was generated for me after added entity framework code-first for SQL Server CE using NuGet. They did no changes to any other file. The file SQLCEEntityFramework.cs was created and placed in App_Start folder.
Does this mean it automatically gets executed or something? The same thing happened when I added Ninject for MVC 3. No code was added to the global.ascx file so I have no idea if its plug and play or I have to configure something.
[assembly: WebActivator.PreApplicationStartMethod(typeof(StackTorrents.WebUI.App_Start.SQLCEEntityFramework), "Start")]
According to:
http://haacked.com/archive/2010/05/16/three-hidden-extensibility-gems-in-asp-net-4.aspx
This new attribute allows you to have
code run way early in the ASP.NET
pipeline as an application starts up.
I mean way early, even before
Application_Start. This happens to
also be before code in your App_code
folder (assuming you have any code in
there) has been compiled. To use this
attribute, create a class library and
add this attribute as an assembly
level attribute. A common place to add
this would be in the AssemblyInfo.cs
class within the Properties folder.
To clarify, it gives you a way of hooking into several application start and application shutdown events WITHOUT having to change any existing code files (previously you had to edit Globals.asax.cs).
This is mostly a big deal when making packages as these events are really useful for bootstrapping Http modules and it is really difficult to write code into existing files.

Resources