What is dependency injection - Sandeep Kanao
Dependency Injection is a technique that decouples the consumer from the actual implementation during design/compile time and binds them at run time.
Based on - "Don't call us, we'll call you" - Hollywood principle...
Dependency injection is basically providing the objects that an object needs (its dependencies) instead of having it construct them itself. It's a very useful technique for testing, since it allows dependencies to be mocked or stubbed out.
public SomeClass() {
myObject = Factory.getObject();
}
This can be troublesome when all you want to do is run some unit tests on SomeClass, especially if myObject is something that does complex disk or network access.
public SomeClass (MyClass myObject) {
this.myObject = myObject;
}
This way, you can create a dummy myObject for unit testing.
ASP.NET MVC Pipeline - Sandeep Kanao
Step 1: The request goes through the ASP.NET stack and is handed over to the routing engine the first thing.
Step 2: Based on the route configuration, the routing engine looks for the appropriate controller. If the controller is found, it is invoked. If not found, a Controller not found is returned by the Routing engine.
Step 3: The Controller interacts with the Model as required. If there is incoming data, Model binding is done by ASP.NET MVC to make the incoming data into a strongly type Model if required.
Step 4: The model if invoked, retrieves or save appropriate data and returns to the controller.
Step 5: The controller then requests for a View with (or without) the data from Model. There may be one or more View engines registered so MVC Cycles through all the View engine until it finds one and renders the view. Then hands over the request to the ViewEngine which returns the Result to the Controller. The Controller send back the Result as a part of the HTTP response.
The takeaway in this diagram is that ASP.NET MVC is dealing with straight HTTP, there is no ViewState munging or other fancy state management in the pipeline
A more detailed view is available in Steven Sanderson’s famous chart (from RedGate’s site).