Spring.NET with MVC3 (Razor) - asp.net-mvc-3

I'm experimenting with ASP.NET MVC3 Razor and I'm fairly impressed. This is the way we'll go.
We use Spring.NET for dependency injection in our framework and I wonder, if it is possible to use it for MVC3 projects as well?
The documentation of Spring.NET is only talking about MVC2, but I guess there will be MVC3 support in future release. Nonetheless I was trying to get it work though. With no success so far.
So my question is, if someone else found a way or workaround or trick to do dependency injection in MVC3 using Spring.NET and if so, how?
I know this is a very general question, but even a honest "sorry this is definitely not possible" or "it should work without any modifications" would help me a lot.
Thanks in advance,
Jan

Yes, even though the the latest Spring.NET release (1.3.1) has explicit support for MVC2, it can also be (pretty easily) used to support MVC3. The IDependencyResolver interface introduced with MVC3 makes IoC integration significantly more straightforward than it had been in the past (offering just one single interception/pluggability point for type resolution where previously there had been multiple places you needed to intercept type resolution calls).
See blog posts like this one: http://blog.alexkyprianou.com/2011/03/07/using-spring-net-with-mvc-3/ for more information and suggestions on how you might go about doing this (its really quite simple compared to the effort/complexity of doing so with MVC1 and MVC2.

It should work without modifications.
After some more investigation and help of colleages I found out, that Spring.NET works with MVC3 - at least as far as I can see it now. My orignal problem was a misformatted xml-file for my injection objects (I didn't post the code in the question).
Still there seem to be issues with object scopes. The scope request doesn't seem to work, since all my objects are still singletons and once created, can not handle more than one request.
I tried to add the well-known attribute singleton="false" and it worked somehow, so my objects will now be created on every request. Good!
However I found out, that Spring.NET's example Spring.MvcQuickStart.2010 also uses the singleton attribute with value false, so probably this is the correct way (and true by default).
I don't know yet, how to handle the session scope, but at least my web application works for requests (singleton="false") and application-wide (no singleton attribute) with Spring.NET and MVC3.
Best,
Jan

Related

Sitecore 7.2 | Drawbacks of using MVC and Web Forms in the same site built with MVC

Question : Downside of using Web forms and MVC in same sitecore instance.
Current Situation : We have a Sitecore 7.2 instance developed using MVC and Glass Mapper. We want to reuse existing component which is already developed in Web Forms using the same sitecore version that we are currently using. What we have done so far: To achieve this we did a small POC and were able to achieve the same. We referred below link at Git to achieve this POC We found few blogs where people have done this but always say that it may not work all the time (and not highlighted which scenarios they fail). What are the drawbacks or possible difficulties that we could face doing this ?.It will be helpful if you can highlight as For example :Workflow does not work or personalization does not work etc. Thanks
I am currently running a Sitecore 7.2 instance with both WebForms and MVC (we actually went the other way- our old code is Webform and with a recent redeisgn we moved to MVC) and its doable, but kind of messy.
The biggest issues we've run into have been when we want to display webform and mvc content on the same page, or have the two code bases communicate in any way. Attempting to have renderings calling both webform and mvc code on the same page was disaster. Likewise trying to have webform-only pages communicate with mvc-only pages (eg. building out submenues, getting field values, etc).
In a way, what ended up happening with us was we had essentially two sites - the webforms and mvc versions - and the two never really merged well together. Our project plan was to move off of Webforms to full MVC, so we accepted this as a reality. I'm not sure how well a permanent mvc-webform crossover solution would work, to be honest.
We had some good luck using the following resources: https://www.packtpub.com/books/content/mixing-aspnet-webforms-and-aspnet-mvc
http://www.sitecore.net/Learn/Blogs/Technical-Blogs/John-West-Sitecore-Blog/Posts/2012/06/Using-Web-Forms-and-MVC-in-a-Single-Solution-with-the-Sitecore-ASPNET-CMS.aspx
It's been messy for us, lots of time keeping pages and code apart, and we are planning on cutting out webforms completely in the near future and going full-mvc. But running both is very doable.

Zend Framework 2 - Rich Components - GUI - editable datagrid, datatable, lists, forms, dialogs, tree-views, autocomplete field

Zend Framework 2 has implemented a lot of stuff for all the layers, but like nothing for GUI.
I am missings things like datagrids, dialogs, tree-views, autocomplete fields and all the stuff one has in JSF and Richfaces.
I thougt maybe extJS could be an alternative, but theres no production ready integration yet.
Why use ZF2 when I have to write code for hours and weeks for such simple things that should already be integrated in an enterprise ready framework ?
I spent very much time now for digging into ZF2 and I learned a lot.
But because of the missing View stuff in ZF2 I'm thinking of changing to another Framework now, after weeks of hard work.
Does someone have a better solution ?
Have a look at this module, you may find what you need :
https://github.com/mwillbanks/ZfcTwitterBootstrap
Also, I suggest you to have a look at the modules page :
http://modules.zendframework.com/
I don't like to answer my own questions, but I want to close this old one and maybe it helps someone else.
At the moment I am very happy with ZfcDatagrid by ThaDafinser.
https://github.com/ThaDafinser/ZfcDatagrid/commits/master
It didn't exist when I asked the question. And as you can see in this great module, it is a lot of work to create such a component for ZF2 and as you can see, it's not just a javascript being served. There's much much more logic behind with pagination, filtering, datasources, output formatting and much more.
You don't want to do this in your controller code, because you want to reuse the grid logic and every grid instance. And you don't want all that logic on client side, because of the same reason.

MVC 3, Entity Framework 4.x, Database First, Desperation

VS2010 Pro + SqlServer Express.
Having been dropped into ASP.NET MVC 3 with no guidance but the web (2 books on order), I can't even get off the ground.
The MVC itself I get. Not a problem.
PHP, Ruby, and even ghastly WebForms firmly tucked into my toolbelt, with a long history of C++ QT client-server development before that.
Tying ASP.NET MVC 3 to a database using EF4 ORM is killing me.
The goals:
Use database modeled by DBA. I can specify all naming conventions, but code first is not an option!
Import to EDMX. This will be regularly updated using VS tools from the DBA's DB, never edited directly.
Generate partial classes from EDMX, for use as model. This will regularly be updated using VS tools, never edited directly.
Use 'buddy' to extend above model class with code as the Controllers/Views need.
Intuitively use the resulting model, pass it to the view, retrieve posts into it for insert/save, etc...
I've seen and read so many blogs, forum posts, walkthroughs, and stack overflow posts regarding this very use case.
I even tried riding the magic unicorn, followed by the latest 4.2beta1 with DbContext generators.
But can't get off the ground.
I follow instructions, but just not understanding how to do anything with it.
What conventions does the 'buddy' require (if any)? How do I use it? How do I get data with it? How do I write data?
Every example looks different. MVC guides are always focused on the UI side. EF guides don't cover usage in the MVC.
These are basic questions, and I'm feeling like the most incompetent idiot in the WWW right now.
Is anyone out there currently using MVC3 & EF4.x in the way I describe above?
This video is a good starting resource. Its a video of a guy creating an app from scratch that uses entity and a sql database (though he makes the db in the video, its still good for seeing some basics in action). You can see how he pulls data from the database, displays it on the page, and saves changes back to the database.
The first question I would ask is why are you stuck on using EF as an ORM or even insisting an ORM at all? I'd choose tools to suit the job here, especially given the constraints of the data layer.
Buddy classes were a concept invented in a day when the main .NET ORMs had no code-first option as ORM-encumbered class instances really don't behave well under things like model binding. Nevermind you could not decorate them with the DataAnnotations one used to indicate fields were required. Typically, the technical requirement is to use [MetadataType] attributes to tie your buddies to your models and perhaps something like AutoMapper to map data to and fro.
All that said, as a guy who has a few apps with lots of buddies and lots of automapping going on, you might want to think otherwise -- it is a bit of a maintenance nightmare. I'm living it.
There are some really good getting-started videos and tutorials right on ASP.NET MVC's site. The "Model (Data)" section is Entity Framework focused and touches on hot/trending topics like Repositories and Units Of Work.

Learning Inversion of Control through Dependency Injection in MVC 3

Can someone please provide me a simple example of DI and IoC?
I understand the first one but was unable to get an implementation of the second one.
I'm working with MVC 3 and I really want to use the IDependencyResolver, but I can't understand how.
Is ninject an option or is it required?
Is there a tutorial like nerdDinner and I wasn't able to find it?
Can somebody give me a link to study it?
In order to grok real world DI and its patterns and anti-patterns quickly, I recommend getting DI in .NET. (I've ordered it already EDIT: And it was a page turner that taught me a lot and should teach people of all experience levels well)
Failing that, read all Mark Seemann's high-rated posts here.
I personally learned from the ninject wiki, but that, while excellent, is Ninject 1.0 specific.
don't use IDependencyResolver. It has nothing to do with Inversion of Control, and it's fundamentally broken. If you want to learn how to use IoC Container properly with MVC 3 see this tutorial (uses Windsor).
This isn't my example, but is one I just ran across while looking for a simple, functional example. It uses NInject and the final IoC functionality of .Net MVC 3.
http://www.shahnawazk.com/2010/12/dependency-injection-in-aspnet-mvc-3.html
Simple downloadable example project at the bottom of the article.
I cant answer for asp related techs, but on the academic side, the fact that you are using DI implies that you have inverted control.
Ill make it explicit -- when you do not invert control, you basically make the various components of an application resolve their own dependencies. When you invert control, you allow the resolving of the dependencies happen at some other layer. That is the 'inversion' of the control.

What new features would you like to see in Asp.net MVC 3?

Asp.net MVC 3 preview 1 was released at the end of last month. Are there any new features you are excited about or any features you would like to see before it is fully released?
Full support for Controllers with Generic Parameters
public GenericController<SomeType> : Controller
Generic controllers are quite possibly the greatest MVC timesaver if your doing a lot or business CRUD. There are so many similarities between the Add methods of almost every MVC project that it makes sense to abstract these operations out in a Controller that fits all scenarios.
Right now its a little hacky to create a generic controller. The MVC engine always gets the name wrong (GenericCo vs. Generic) and without full support plugin and libraries that interact with controllers just fall over when they encounter a generic one.
Make Dropdowns easier to work with
As a professional MVC tag watcher I've noticed that working with dropdowns is one of the most repeated questions on SO. The amount of Dropdown questions is a strong indication that something should be done to make it easier or less ... complex?
make checkbox list easy to work with
add T4MVC to the official release
add official helpers for OData
support one javascript library either MS Ajax or jQuery(preferably)
I wish they can add something to help developer to migrate their previous ASP.NET WebForms application.

Resources