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 ?
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.
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.
SetResolver Method (Object) Provides a registration point for dependency resolvers using the provided common service locator when using a service locator interface.
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>();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With