Is inversion of control implemented in Django? - asp.net-mvc

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 ?

Related

How can I automatically register services in .net core dependency injection?

My team is looking at converting our solution to .net core and we are trying to decide whether we should stick with StructureMap as our DI tool or use Microsoft's one that is provided with .net core. One thing we have with StructureMap is the ability to automatically register our services based on naming conventions (something like this):
Scan(s =>
{
s.WithDefaultConventions();
s.AssembliesFromApplicationBaseDirectory(AssemblyFilter);
});
Is there a way to do this with Microsoft's DI container out of the box?

What is similar to .NET MVC in java EE to implement a web application

I need to build a MVC web application using java EE. I have not any knowledge about how to implement it using java. But I have developed some applications using .Net MVC and entity framework. I have following questions.
Is there a framework for developing MVC applications in java EE?
What is the similar(suitable) framework for EntityFramework in java? (is hibernate possible?)
Can web services also be implemented like in .NET MVC as well?
Q: Is there a framework for developing MVC applications in java EE?
Java EE inherently includes MVC framework called JavaServer Faces (JSF). It consists of business layer usually represented with EJBs (Enterprise Java Beans), JPA and DAOs as a model, XHTML pages with Facelets tags as a view and FacesServlet as a controller. You can also have a look at Spring and Struts MVC frameworks.
Q: What is the similar(suitable) framework for EntityFramework in java? (is hibernate possible?)
Java EE comes with JPA which stands for Java Persistence API. There are few implementations of this API, Hibernate that you mentioned is one of the most used. Hibernate started as a separate project aimed to bring ORM to Java world, and recently included full JPA support. However, Hibernate brings its own annotations and methods that make this implementation more powerful but if you rely on them, you cannot easily switch later to some other JPA implementation. Default JPA implementation is called EclipseLink (previously known as TopLink).
Q: Can web services also be implemented like in .NET MVC as well?
Yes. JAX-WS specification and Metro implementation aim to gain interoperability with other Web service frameworks such as WCF that you are probably familiar with. You start with either WSDL or your Web service code and generate the code/WSDL using the tools provided. There is also JAX-RS which is suitable if you like to build RESTful Web services.
See also:
JavaServer Faces technology
Why another MVC?

KooBoo & Servicestack Architecture / Design questions

I wanna use KooBoo for my web platform and for that combine it with Servicestack (Servicestack).
Servicestack should act as the REST API framework and Kooboo as the user frontend framework.
I would like to build a independent service layer within that, where Kooboo controllers and servicestack services are leliyng on and share for instance the same session.
So my questions are
How to integrate a webservice framework in Kooboo in general (Change
source, Module, Plugin...)
How to use / integrate layered architecture ? (Because you persist Models directly with your data API, is there a way or what is the recommended way of usinf business objects and ViewModels separated)
Can I integrate other editors instead of tinyMCE
When I use other js framworks like angularJS or kendoUI, can I still use the "inline edit" functions ?
I know, a lot of questions. If you want me to split up these into separate threads I will do that of course!
I've never heard of KooBoo before but seeing that it's built on ASP.NET MVC, the ServiceStack Integration and MVC Integration docs shows how you can access ServiceStack's dependencies, plugins, execute Services etc. from outside of ServiceStack, e.g from within ASP.NET MVC.
The documentation goes through to explain different ways you can integrate with ServiceStack from an ASP.NET MVC web application and also includes a live demo of different techniques at http://mvc.servicestack.net (source code).

Configure IoC Container in hybrid ASP.NET WebForms MVC project

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

Why is MVC4 using the Service Locator Anti-Pattern?

After reading "Dependency Injection in .NET" by Mark Seemann I stay away from the Service Locator which is an anti-pattern.
Upon reading the release notes on MVC 4 I see:
Improved Inversion of Control (IoC) via DependencyResolver: Web API
now uses the service locator pattern implemented by MVC’s dependency
resolver to obtain instances for many different facilities.
Thus I'm left curious and confused why Microsoft would use a service locator in 2012.
That's an implementation detail that you shouldn't care about. The important thing is that now that the Web API uses the DependencyResolver to resolve dependencies for many different facilities, you will be able to use a real dependency injection whenever you want to plug into those facilities. So in your code you will be using a real dependency injection. If Microsoft didn't use the DependencyResolver then it would have been you that must have used it (as a service locator anti-pattern) in your code in order to resolve dependencies when you want to implement some custom functionality. This would have been bad for you. Now it's bad for Microsoft but you don't care about them.
Thus I'm left curious and confused why Microsoft would use a service locator in 2012.
Because designing a framework is not the same as designing an application using a framework. There are some different things to take into consideration when designing a reusable framework such as ASP.NET MVC rather than just what's written in the books. Some example is to design the framework in such a way that a person using this framework will be able to take advantage of the best practices written in the books in his code using this framework.
As Darin points out, ASP.NET MVC 4 is a Framework and is container agnostic. That's why it provides a service locator in the form of IDependencyResolver. This allows anyone to plug in their container of choice.
However, I wouldn't call this an anti pattern. This allows you to use the container of your choice, but it doesn't force you the application developer to use service location. If the framework forced the developer to use Service Location, then I would call it an anti-pattern. But the developer who builds an ASP.NET MVC application is free to use DI via constructor injection, property setup, or service location. It's their choice.
Look at all the ASP.NET MVC examples of dependency injection published by me or the ASP.NET MVC team. In pretty much all cases, they're using constructor injection. They're not using service location.
In fact, most of the ASP.NET MVC source code itself doesn't use service location to retrieve dependencies. There's a few key places where the MVC calls into the service locator for legacy APIs and such. But that's about it.

Resources