Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.net mvc 4 dependency resolver

I am new to ASP.NET MVC 4. I have used a custom dependency resolver in my ASP.NET MVC 4 project in order to use Dependency injection framework.

What is the role of dependency resolver in ASP.NET MVC 4 ?

like image 475
Aslam Jiffry Avatar asked Nov 20 '13 02:11

Aslam Jiffry


People also ask

What is dependency resolver in MVC?

A dependency resolver is just a service locator integrated with the ASP.NET MVC codebase. Resolvers are a way to add the implementation of the Dependency Inversion principle into an existing (large) codebase.

Can we use dependency injection in ASP.NET MVC?

The Dependency Injection (DI) Design Pattern The Dependency Resolver in ASP.NET MVC can allow you to register your dependency logic somewhere else (e.g. a container or a bag of clubs). The advantages of using Dependency Injection pattern and Inversion of Control are the following: Reduces class coupling.

What method does the dependency resolver use to acquire instances of objects?

SetResolver Method (Object) Provides a registration point for dependency resolvers using the provided common service locator when using a service locator interface.


1 Answers

It allows you to abstract away from Dependency Injection implementation. Later if you decide to switch from Unity to Windsor, you can do it much easier without having to re-write lots of code

It means that you can resolve your instances using this code

DependencyResolver.Current.GetService<IMyController>();
like image 190
evhen14 Avatar answered Sep 22 '22 18:09

evhen14