ninject

How to store Ninject Kernel in an ASP.NET Application?

青春壹個敷衍的年華 提交于 2020-01-02 10:01:38
问题 I'm really confused about small, partial, one-file examples where there's a Ninject kernel everywhere without showing how to really get to that kernel in the application. (1) Should we instantiate one Kernel and keep it in "static" context? Or should we instantiate a different one on every request (*in Application_BeginRequest*) (2) If it is "kernel per request", then why Initialize() method of the NinjectWebCommon.cs ( gets when you install the NuGet package ) is called on Application_Start

Register Generic Type in Unity Based On Concrete Type

爷,独闯天下 提交于 2020-01-02 06:29:23
问题 I'm trying to emulate a behavior that I can configure in Ninject, only using Unity instead. I am attempting to use the Cached Repository Pattern, given the following classes and interface: public interface IRepository<T> { T Get(); } public class SqlRepository<T> : IRepository<T> where T : new() { public T Get() { Console.WriteLine("Getting object of type '{0}'!", typeof(T).Name); return new T(); } } public class CachedRepository<T> : IRepository<T> where T : class { private readonly

WebAPI CORS and Ninject

点点圈 提交于 2020-01-02 06:20:10
问题 I have a c# WebAPI project that has ninject and all the get functions are working. However every time i try to post i get a "Method Not Allowed" response from the api. I have read a few places that this is cause when the api is refusing cross origin calls. So i used the package manager console and installed the Microsoft.AspNet.WebApi.Cors nugent package and followed the instructions as per the article http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api. My

Ninject: Choosing the wrong constructor

谁说胖子不能爱 提交于 2020-01-02 03:10:12
问题 I have an ASP.NET MVC 3 application with Ninject v2.2.1.4. Everything was working great and then suddenly we started seeing Ninject attempting to create our DbContext using a constructor with a parameter over the parameterless constructor. Here are the bindings: kernel.Bind<MyContext>().ToSelf().InRequestScope(); kernel.Bind<IUnitOfWork>().ToMethod(ctx => ctx.Kernel.Get<MyContext>()); kernel.Bind<DbContext>().ToMethod(ctx => ctx.Kernel.Get<MyContext>()); The MyContext is a DbContext object

How do I inject into some generic asp.net http handler using Ninject?

北慕城南 提交于 2020-01-02 02:53:06
问题 I'm a newbie using Ninject and I can't figure out how to inject into my generic http handler. I have a MVC3 project and I'm injecting my services into controllers with no problem at all. This is what I got in my Ninject App_start class for registering services: private static void RegisterServices(IKernel kernel) { kernel.Bind<NLSubscriber.Core.Service.Repository.INLUserRepository>().To<NLSubscriber.Core.Service.Repository.EFDAL.EFNLUserRepository>().InRequestScope(); kernel.Bind<Neticon.Mvc

Assembly added via Add Reference not copied to output directory unless referred to in code

偶尔善良 提交于 2020-01-02 00:55:09
问题 Situation: Project 1 is an assembly in the solution Project 2 is an executable assembly project in the same solution Project 2 has a project reference (via Add Reference) to Project 1 Project 2 does not directly refer to namespaces/types in Project 1 in the code Project 2 uses Ninject to dynamically load Project 1 and use the implementation classes within it Problem: Even though Copy Local is set to True for the reference, and the referenced assembly does not exist in the GAC, the referenced

Bind multiple implementations to the same interface with ninject

白昼怎懂夜的黑 提交于 2020-01-01 23:55:53
问题 Why is it not possible for me to do the following in Ninect? Kernel.Bind<IPresenter>.To<DefaultPresenter>(); Kernel.Bind<IPresenter>.To<DashboardPresenter>(); Kernel.Bind<IPresenter>.To<HeartRatePresenter>(); Kernel.Bind<IPresenter>.To<GPSPresenter>(); Each of the 4 implementations have a different constructor that expect a different type. When i attempt this, Ninject throws an exception telling me that i cannot bind to the same interface more than once. In a class called Presentable which

HttpConfiguration.get_ServiceResolver() Missing

£可爱£侵袭症+ 提交于 2020-01-01 18:57:08
问题 I am wiring up Ninject with MVC4 and have it working to the point it's trying to actually resolve dependencies. However, I am getting the following exception: Method not found: 'System.Web.Http.Services.DependencyResolver System.Web.Http.HttpConfiguration.get_ServiceResolver()'. Anyone ran into this and have a work around? 回答1: GlobalConfiguration.Configuration.ServiceResolver was replaced with GlobalConfiguration.Configuration.DependencyResolver in the RC. So I guess the Ninject package you

Ninject Factory on Derived Types

浪子不回头ぞ 提交于 2020-01-01 17:28:10
问题 I'm looking at the Ninject Factory extension at the following link: http://www.planetgeek.ch/2011/12/31/ninject-extensions-factory-introduction/ I'm trying to wrap my head around the extension and see if it actually fits into what I'm trying to do. Can the factory extension create different types based on a parameter that is passed in? Example: class Base {} class Foo : Base {} class Bar : Base {} interface IBaseFactory { Base Create(string type); } kernel.Bind<IBaseFactory>().ToFactory();

Using Ninject 2.0 with ASP .Net 3.5

天涯浪子 提交于 2020-01-01 16:49:44
问题 I am trying to use Ninject 2.0 with Asp .Net 3.5 web application. Following are the DLLS and it's versions I am using. Ninject.dll - v2.0.0.0 Ninject.Extensions.Logging.dll v2.0.0.0 Ninject.Web.dll v1.0.0.0 In my global.ascx.cs I have following method. protected override IKernel CreateKernel() { IKernel kernel = new StandardKernel(); kernel.Bind<IDataAccess>().To<DataAccessEntBlock>().InSingletonScope(); return kernel; } When I run the application I get following error. Error activating