How is a hybrid ASP.NET WebForms / ASP.NET MVC supposed to configure an IoC container, such as StructureMap? For example, if I was to apply StructureMap to an ASP.NET MVC app, I'd simply use the Dependency Resolver in ASP.NET MVC and I'd be all set. And in an ASP.NET WebForms app, I would use the BuildUp(this) feature of StructureMap in some sort of Base Page class that UI.Page would extend or use Global.asax. But what would you do in the case of a hybrid application? How would something like this look? Would I use global.asax for both in some way?
You're answering your own question:
In Web Forms, use the build up functionality (for example you can have a base Page class and a base User control class. Don't forget this one)
In MVC, you can use the dependency resolver.
There's no problem using both at the same time on a hybrid web application.
There are other techniques for web pages that involve handlers. An interesting article:
Inversion of control and dependency injection with Web Forms in 2 acts
Related
I come from a .net background and I used to work with asp.net MVC that implemented dependency injection using UnityContainer, that did the mappings between the interfaces and their implementation. Now I am working with django and I wonder if there is something similar ?
I just wanted to clarify my understanding of ASP .NET MVC (current version is 4).
I was reading this article on How does ASP.NET MVC work?
So, how does ASP.NET know how to route requests to MVC? The answer lies in web.config. There is a new http module added to modules collection in ASP.NET MVC projects
So basically an mvc application is implemented as an HTTPModule or at least the url routing portion of an mvc app?
Would it be possible for one to create and register a custom routing module and then possibly create their own micro mvc framework like Sinatra in Ruby or Slim in PHP?
The Url routing is in fact it's own ASP.NET module. It's used both for MVC and WebForms (and can be used for other ASP.NET application types too). The routing is included in the System.Web assembly. More info about the routing features can be found at MSDN.
MVC is implemented using a IHttpHandler. The implementation can be found here.
Now for the actual question:
Would it be possible for one to create and register a custom routing module and then possibly create their own micro mvc framework like Sinatra in Ruby or Slim in PHP?
Yes. It's fully possible. You need to create your own class that implements IRouteHandler. Then simply register routes using that handler.
I'm a little new to DI containers like StructureMap and I've been using it for a short time with asp.net mvc applications. Now I'm splitting my architecture that will have a WCF service layer and a sort of consumers like ASP.NET MVC app, Silverlight App, And Winfors/WPF App. When using SM with asp.net mvc I've been initializing the IOC by the app startup of the asp.net mvc, now, using for many project I can't think a good place where the IOC config should be located.
I want to make DI in the services layer too(injecting Repositories).
In this scenario, where I do load my IOC config and how I'll use across the projects(like the controller factory is needed only in the asp.net mvc app)?
You create and configure a container per application.
If you have an ASP.NET MVC site, you create and configure a container instance in Global.asax.
In a WCF service you can write a custom ServiceHostFactory that spins up a custom ServiceHost that again attaches an appropriate IInstanceProvider that uses a container instance to wire up the WCF service. That sounds complicated, and it definitely is more complicated than it ought to be. I have previously touched on this subject in a completely different context, but this blog post should give you some hints - particularly if you keep in mind that delegates are anonymous interfaces.
What are the best practices for ASP.NET MVC and Silverlight usage in a web application? To be specific which libraries/frameworks (like prism) should be used in order to make the application unit testable and develop rapid? How one should pass data to the silverlight part from asp.net mvc (binding if possible?) and vice verse (from asp.net to silverlight)?
The Entity Framework with RIA services is made precisely for this purpose.
I propose:
asp.net mvc as service layer
silverlight as client
linq2sql for datalayer
nunit for testing
I found that Asp.net Mvc controller can serve both Asp.net Mvc View and Silverlight application via DynamicActionResult(It can be Simple Action Result or Json Action Result depend on request type). So, I have 3 options for creating middle-tier for Silverlight application.
Pure WCF Service Every request to WCF must be declare in interface. So, it's strongly-typed connection.
Asp.net MVC Controller It can serve both Asp.net MVC View and Silverlight application at the same time.
Using both of them I found that it's possible to doing this by using the answer in the following link. I think, It doesn't good idea for creating both of them.
WCF Service with Asp.net MVC application
Which's the best performance between WCF Service and Asp.net MVC Controller?
Thanks,
Do you have the kind of service that would benefit from caching? If so, my testing says that MVC with Output Caching turned on is very much faster than WCF.