I'm using Ninject in an MVC project and I've used the autoregistration features in Ninject.Mvc and have my bindings set up in my application class. However, I have a place where I want to create an instance separate from those bindings. In StructureMap, you can do var foo = ObjectFactory.GetInstance<IFoo>();
and it will resolve it for you. Is there an equivalent in Ninject 2? I can't seem to find it anywhere.
相关问题
- Slow loading first page - ASP.NET MVC
- Validation Attribute get triggered two times
- Constructor Argument Enums and Magic Strings
- What is the equivalent of Container.GetAllInstance
- C# method that is executed after assembly is loade
相关文章
- Injecting an IEnumerable into a constructor with a
- NHibernate throwing Session is closed
- Ninject Contextual Binding at RunTime
- Ninject.Web.PageBase still resulting in null refer
- How do you use method injection with Ninject?
- How to use Ninject to inject services into an auth
- Castle Windsor Typed Factory Facility equivalents
- Convention based binding of constructor string arg
AFAIK, NInject doesn't have static method like this so all resolving should go to some kernel.
But you can implement it easily;
Although, IMO, NInject is much more useful as DI container than as service locator.
You can also use Common Service Locator as an abstraction layer for Ninject IOC which offers what you want. The advantage is that you can later switch container if it does not fit your needs anymore.
In your code you can use something like this: