ninject-2

Ninject giving NullReferenceException

被刻印的时光 ゝ 提交于 2019-12-10 11:27:43
问题 I'm using asp.net MVC 2 and Ninject 2. The setup is very simple. Controller calls service that calls repository. In my controller I use inject to instantiate the service classes with no problem. But the service classes don't instantiate the repositories, giving me NullReferenceException. public class BaseController : Controller { [Inject] public IRoundService roundService { get; set; } } This works. But then this does not... public class BaseService { [Inject] public IRoundRepository

I need more Ninject practical examples

无人久伴 提交于 2019-12-09 15:59:12
问题 In the past, I used swiftsuspenders that is an actionscript 3 IoC controller. Basically the first version of switfsuspender had something similar to the Ninject kernel that was called injector. If I wanted to create an application injector (with let's say the most relevant mappings to be used throughout the application), I had to inject the injector itself in the application classes. I am wondering now what is the practice to use kernel.get<> among several classes in the application. Should I

Ninject.Extensions.Logging.Log4net unexpected behavior

可紊 提交于 2019-12-09 11:57:57
问题 I am having a problem using Log4Net (1.2.10) through Ninject's (2.2.1.4) Extensions.Logging.Log4net (2.2.0.4), as installed through NuGet. When I access Log4Net directly: var logger = log4net.LogManager.GetLogger("Log4NetLoggerTest"); logger.Debug("foo { bar"); The result is: 2011-08-29 10:02:02,071 [9] DEBUG Log4NetLoggerTest foo { bar However, when the logger is accessed through Ninject: using (IKernel kernel = new StandardKernel()) { var ninjectLogger = kernel.Get<NinjectLoggerTest>();

No Source Available Error With Ninject When Debugging Code

六月ゝ 毕业季﹏ 提交于 2019-12-09 01:35:10
问题 I have used NuGet to install the latest version of Ninject (v2.2.1.4). I have then created my own NinjectDependencyResolver (credit to Adam Freeman & Steve Sanderson): public class NinjectDependencyResolver : IDependencyResolver { private IKernel kernel; public NinjectDependencyResolver() { kernel = new StandardKernel(); AddBindings(); } public object GetService(Type serviceType) { return kernel.TryGet(serviceType); } public IEnumerable<object> GetServices(Type serviceType) { return kernel

Having both an InRequestScope and InTransientScope for Ninject resolving to same type

会有一股神秘感。 提交于 2019-12-08 05:24:48
问题 I've got a Ninject setup that creates a JobContext resolver InRequestScope() This works just fine, however, I have a very specific call in the Website that requires me to loop through a few databases (all the data in databases by year). I couldn't quite figure out what was going on because I had forgotten that the JobContext was InRequestScope but the last block of code was not acting how I thought it should. Here is the setup //Ninject module Bind<Data.IJobContext>().To<Data.JobContext>()

Rhino.Security and IEntityInformationExtractor

让人想犯罪 __ 提交于 2019-12-07 21:15:34
问题 I've recently downloaded Rhino.Security and I am trying to implement permissions on a entity. Since I like Ninject (v2) I would like to put together a simple example to start with. In my NinjectModule I've bound the repository and the services: Bind<ISessionFactory>() .ToProvider(new SessionFactoryProvider()) .InSingletonScope(); Bind<ISession>().ToProvider(new SessionProvider()) .InSingletonScope(); Bind<IAuthorizationRepository>() .To<AuthorizationRepository>() .InSingletonScope(); Bind

Ninject InRequestScope missing

自古美人都是妖i 提交于 2019-12-06 16:31:57
问题 Have a couple of questions regarding the latest version (2.2.1.4) of ninject. Was trying to Bind a Linq2sql DataContext to a concrete implementation InRequestScope (in a class library project) Bind<DataContext>().To<MoneywatchDataContext>() but could not find InRequestScope method ended up doing this, Bind<DataContext>().To<MoneywatchDataContext>().InScope(ctx => HttpContext.Current) Just wanted to find out if: If this will behave exactly like the InRequestScope Method. That it will gurantee

Ninject 2.2 multiple bindings

狂风中的少年 提交于 2019-12-06 08:22:00
问题 I recently updated ASP.NET MVC 3 app to Ninject 2.2. Previously I had the following interface to implementation binding in my main app: Bind(typeof(IMyInterface<>)).To(typeof(MyImplementation<>)).InRequestScope(); In addition, I had the following in a different assembly that was being loaded by my main app: var arg = new ConstructorArgument("info", "something"); Bind<IMyInterface<MyClass>>().To<MyImplementation<BlogComment>>().WithParameter(arg); This worked fine previously and the more

Rhino.Security and IEntityInformationExtractor

强颜欢笑 提交于 2019-12-06 08:00:45
I've recently downloaded Rhino.Security and I am trying to implement permissions on a entity. Since I like Ninject (v2) I would like to put together a simple example to start with. In my NinjectModule I've bound the repository and the services: Bind<ISessionFactory>() .ToProvider(new SessionFactoryProvider()) .InSingletonScope(); Bind<ISession>().ToProvider(new SessionProvider()) .InSingletonScope(); Bind<IAuthorizationRepository>() .To<AuthorizationRepository>() .InSingletonScope(); Bind<IPermissionsService>() .To<PermissionsService>() .InSingletonScope(); Bind<IAuthorizationService>() .To

Get ninject factory extension to allow factory parameters be passed to dependencies

此生再无相见时 提交于 2019-12-06 04:36:33
问题 Using the Ninject Factory extension, you can automatically generate factories, and let the factory pass parameters to the class' constructor. The following test passes: public interface IBar { int Foo { get; } } public class Bar : IBar { int _foo; public Bar(int foo) { _foo = foo; } public int Foo { get { return _foo; } } } public interface IBarFactory { IBar CreateTest(int foo); } [Test] public void ExecuteTest() { var kernel = new StandardKernel(); kernel.Bind<IBar>().To<Bar>(); kernel.Bind