Reputation: 2362
How is it possible to use Ninject inside ASP.NET MVC 3 to instantiate objects manually? Something as
"NinjectObject".Resolve<IMyService>();
Thank you & regards
Upvotes: 3
Views: 4155
Reputation: 1039248
It is better to inject dependencies instead of resolving them. Service Locator is an anti-pattern. You could for example use the following:
IMyService myService = DependencyResolver.Current.GetService<IMyService>();
But please do not use it. That's an anti-pattern.
Dependency injection is the preferred way. You should have the constructor of the class that needs this dependency take an IMyService
instead of having the class fetch this dependency.
Upvotes: 14